From 46eab4d838fabecfb7b6f42debdaaf5e53b8190f Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 21 May 2013 16:35:22 -0400 Subject: [PATCH] dbus-launch: Add an option --no-bus-fork Previously, dbus-launch passed --fork to dbus-daemon, which (among other things) causes it to open /dev/null for stdin/stdout/stderr. Then, session components activated by dbus-daemon simply inherit these defaults. In a systemd environment, we really want the output of everything to be hooked up to the journal by default. At present, gdm launches dbus-daemon for the user session, and I will be modifying it to pass this flag by default. This solves the "Where the $#%@ are my error messages?" issue I was having while debugging something else... https://bugs.freedesktop.org/show_bug.cgi?id=64843 --- tools/dbus-launch.c | 65 +++++++++++++++++++++++++++++++------------------- 1 files changed, 40 insertions(+), 25 deletions(-) diff --git a/tools/dbus-launch.c b/tools/dbus-launch.c index b2ffe41..3c0cd03 100644 --- a/tools/dbus-launch.c +++ b/tools/dbus-launch.c @@ -181,7 +181,7 @@ verbose (const char *format, static void usage (int ecode) { - fprintf (stderr, "dbus-launch [--version] [--help] [--sh-syntax] [--csh-syntax] [--auto-syntax] [--exit-with-session]\n"); + fprintf (stderr, "dbus-launch [--version] [--help] [--sh-syntax] [--csh-syntax] [--auto-syntax] [--exit-with-session] [--no-bus-fork]\n"); exit (ecode); } @@ -596,6 +596,7 @@ kill_bus_when_session_ends (void) static void babysit (int exit_with_session, + int no_bus_fork, pid_t child_pid, int read_bus_pid_fd) /* read pid from here */ { @@ -659,11 +660,14 @@ babysit (int exit_with_session, verbose ("=== Babysitter's intermediate parent continues again\n"); - if (do_waitpid (child_pid) < 0) + if (!no_bus_fork) { - /* shouldn't happen */ - fprintf (stderr, "Failed waitpid() waiting for bus daemon's parent\n"); - exit (1); + if (do_waitpid (child_pid) < 0) + { + /* shouldn't happen */ + fprintf (stderr, "Failed waitpid() waiting for bus daemon's parent\n"); + exit (1); + } } verbose ("Babysitter's intermediate parent exiting\n"); @@ -674,25 +678,32 @@ babysit (int exit_with_session, /* Child continues */ verbose ("=== Babysitter process created\n"); - verbose ("Reading PID from bus\n"); - - switch (read_pid (read_bus_pid_fd, &bus_pid_to_kill)) + if (no_bus_fork) { - case READ_STATUS_OK: - break; - case READ_STATUS_EOF: - fprintf (stderr, "EOF in dbus-launch reading PID from bus daemon\n"); - exit (1); - break; - case READ_STATUS_ERROR: - fprintf (stderr, "Error in dbus-launch reading PID from bus daemon: %s\n", - strerror (errno)); - exit (1); - break; + bus_pid_to_kill = child_pid; } + else + { + verbose ("Reading PID from bus\n"); - verbose ("Got PID %ld from daemon\n", - (long) bus_pid_to_kill); + switch (read_pid (read_bus_pid_fd, &bus_pid_to_kill)) + { + case READ_STATUS_OK: + break; + case READ_STATUS_EOF: + fprintf (stderr, "EOF in dbus-launch reading PID from bus daemon\n"); + exit (1); + break; + case READ_STATUS_ERROR: + fprintf (stderr, "Error in dbus-launch reading PID from bus daemon: %s\n", + strerror (errno)); + exit (1); + break; + } + + verbose ("Got PID %ld from daemon\n", + (long) bus_pid_to_kill); + } if (exit_with_session) { @@ -815,6 +826,7 @@ main (int argc, char **argv) int bourne_shell_syntax = FALSE; int auto_shell_syntax = FALSE; int autolaunch = FALSE; + int no_bus_fork = FALSE; int requires_arg = FALSE; int close_stderr = FALSE; int i; @@ -853,6 +865,8 @@ main (int argc, char **argv) exit_with_session = TRUE; else if (strcmp (arg, "--close-stderr") == 0) close_stderr = TRUE; + else if (strcmp (arg, "--no-bus-fork") == 0) + no_bus_fork = TRUE; else if (strstr (arg, "--autolaunch=") == arg) { const char *s; @@ -1038,6 +1052,7 @@ main (int argc, char **argv) if (ret == 0) { + const char *fork_option = no_bus_fork ? "--nofork" : "--fork"; /* Child */ #define MAX_FD_LEN 64 char write_pid_fd_as_string[MAX_FD_LEN]; @@ -1077,7 +1092,7 @@ main (int argc, char **argv) * and will also reap the pre-forked bus * daemon */ - babysit (exit_with_session, ret, + babysit (exit_with_session, no_bus_fork, ret, bus_pid_to_babysitter_pipe[READ_END]); exit (0); } @@ -1106,7 +1121,7 @@ main (int argc, char **argv) { execl (TEST_BUS_BINARY, TEST_BUS_BINARY, - "--fork", + fork_option, "--print-pid", write_pid_fd_as_string, "--print-address", write_address_fd_as_string, config_file ? "--config-file" : "--session", @@ -1121,7 +1136,7 @@ main (int argc, char **argv) execl (DBUS_DAEMONDIR"/dbus-daemon", DBUS_DAEMONDIR"/dbus-daemon", - "--fork", + fork_option, "--print-pid", write_pid_fd_as_string, "--print-address", write_address_fd_as_string, config_file ? "--config-file" : "--session", @@ -1140,7 +1155,7 @@ main (int argc, char **argv) */ execlp ("dbus-daemon", "dbus-daemon", - "--fork", + fork_option, "--print-pid", write_pid_fd_as_string, "--print-address", write_address_fd_as_string, config_file ? "--config-file" : "--session", -- 1.7.1