319
get_launch_environment (GdmLaunchEnvironment *launch_environment,
320
gboolean start_session)
325
hash = build_launch_environment (launch_environment, start_session);
327
env = g_ptr_array_new ();
328
g_hash_table_foreach (hash, (GHFunc)listify_hash, env);
329
g_hash_table_destroy (hash);
331
g_ptr_array_add (env, NULL);
337
stop_dbus_daemon (GdmLaunchEnvironment *launch_environment)
341
if (launch_environment->priv->dbus_pid > 0) {
342
g_debug ("GdmLaunchEnvironment: Stopping D-Bus daemon");
343
res = gdm_signal_pid (-1 * launch_environment->priv->dbus_pid, SIGTERM);
345
g_warning ("Unable to kill D-Bus daemon");
347
launch_environment->priv->dbus_pid = 0;
354
rotate_logs (const char *path,
359
for (i = n_copies - 1; i > 0; i--) {
363
name_n = g_strdup_printf ("%s.%d", path, i);
365
name_n1 = g_strdup_printf ("%s.%d", path, i - 1);
367
name_n1 = g_strdup (path);
370
VE_IGNORE_EINTR (g_unlink (name_n));
371
VE_IGNORE_EINTR (g_rename (name_n1, name_n));
377
VE_IGNORE_EINTR (g_unlink (path));
381
const char *username;
384
const char *log_file;
388
spawn_child_setup (gpointer user_data)
390
SpawnChildData *data = user_data;
392
if (data->uid != 0) {
393
if (setgid (data->gid) < 0) {
397
if (initgroups (data->username, data->gid) < 0) {
401
if (setuid (data->uid) < 0) {
405
gid_t groups[1] = { 0 };
407
if (setgid (0) < 0) {
408
/* Don't error out, it's not fatal, if it fails we'll
412
/* this will get rid of any suplementary groups etc... */
413
setgroups (1, groups);
420
/* Terminate the process when the parent dies */
421
#ifdef HAVE_SYS_PRCTL_H
422
prctl (PR_SET_PDEATHSIG, SIGTERM);
425
if (data->log_file != NULL) {
428
rotate_logs (data->log_file, MAX_LOGS);
430
VE_IGNORE_EINTR (g_unlink (data->log_file));
431
VE_IGNORE_EINTR (logfd = open (data->log_file, O_CREAT|O_APPEND|O_TRUNC|O_WRONLY|O_EXCL, 0644));
434
VE_IGNORE_EINTR (dup2 (logfd, 1));
435
VE_IGNORE_EINTR (dup2 (logfd, 2));
442
spawn_command_line_sync_as_user (const char *command_line,
445
const char *username,
447
const char *runtime_dir,
448
const char *log_file,
456
GError *local_error = NULL;
457
gboolean ret = FALSE;
460
memset (&data, 0, sizeof (data));
463
data.username = username;
464
data.log_file = log_file;
466
g_debug ("GdmLaunchEnvironment: Changing (uid:gid) for child process to (%d:%d)",
472
if (! g_shell_parse_argv (command_line, NULL, &argv, &local_error)) {
473
g_warning ("Could not parse command: %s", local_error->message);
474
g_propagate_error (error, local_error);
479
if (!g_spawn_sync (NULL,
489
g_warning ("Could not spawn command: %s", local_error->message);
490
g_propagate_error (error, local_error);
502
parse_value_as_integer (const char *value,
505
char *end_of_valid_int;
510
long_value = strtol (value, &end_of_valid_int, 10);
512
if (*value == '\0' || *end_of_valid_int != '\0') {
516
int_value = long_value;
517
if (int_value != long_value || errno == ERANGE) {
527
parse_dbus_launch_output (const char *output,
532
gboolean ret = FALSE;
534
GMatchInfo *match_info = NULL;
536
re = g_regex_new ("DBUS_SESSION_BUS_ADDRESS=(.+)\nDBUS_SESSION_BUS_PID=([0-9]+)", 0, 0, NULL);
537
g_assert (re != NULL);
539
g_regex_match (re, output, 0, &match_info);
540
if (!g_match_info_matches (match_info)) {
541
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
542
"Unable to parse dbus-launch output: %s", output);
546
if (addressp != NULL) {
547
*addressp = g_match_info_fetch (match_info, 1);
553
result = parse_value_as_integer (g_match_info_fetch (match_info, 2), &pid);
563
if (match_info != NULL)
564
g_match_info_free (match_info);
572
start_dbus_daemon (GdmLaunchEnvironment *launch_environment,
577
gboolean ret = FALSE;
579
char *std_out = NULL;
580
char *std_err = NULL;
581
GPtrArray *env = NULL;
583
g_debug ("GdmLaunchEnvironment: Starting D-Bus daemon");
585
env = get_launch_environment (launch_environment, FALSE);
587
if (!spawn_command_line_sync_as_user (DBUS_LAUNCH_COMMAND,
588
uid, gid, launch_environment->priv->user_name,
589
launch_environment->priv->x11_display_seat_id,
590
launch_environment->priv->runtime_dir,
599
/* pull the address and pid from the output */
600
if (!parse_dbus_launch_output (std_out,
601
&launch_environment->priv->dbus_bus_address,
602
&launch_environment->priv->dbus_pid,
606
g_debug ("GdmLaunchEnvironment: Started D-Bus daemon on pid %d", launch_environment->priv->dbus_pid);
610
g_ptr_array_foreach (env, (GFunc)g_free, NULL);
611
g_ptr_array_free (env, TRUE);
619
297
on_session_setup_complete (GdmSession *session,
620
298
const char *service_name,