From 7e16acf8b471522f7f1232f97cf520e3c6365dd6 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 5 Jun 2013 18:33:07 +0100 Subject: [PATCH 1/2] dbus-launch: add --exit-with-x11 option This is more suitable for distributions' Xsession scripts: it verifies that X is already available, and so never results in an attempt to poll stdin. Reviewed-by: Will Thompson Bug: https://bugs.freedesktop.org/show_bug.cgi?id=39197 [reformatted for Docbook man page -smcv] --- doc/dbus-launch.1.xml.in | 34 +++++++++++++++++++++++++++------- tools/dbus-launch.c | 33 +++++++++++++++++++++++++++------ 2 files changed, 54 insertions(+), 13 deletions(-) diff --git a/doc/dbus-launch.1.xml.in b/doc/dbus-launch.1.xml.in index 727495b..2d1b3da 100644 --- a/doc/dbus-launch.1.xml.in +++ b/doc/dbus-launch.1.xml.in @@ -25,6 +25,7 @@ --csh-syntax --auto-syntax --exit-with-session + --exit-with-x11 --autolaunch=MACHINEID --config-file=FILENAME PROGRAM @@ -208,16 +209,35 @@ the --session argument. See the man page for dbus-daemon + - - -If this option is provided, a persistent "babysitter" process will be -created that watches stdin for HUP and tries to connect to the X -server. If this process gets a HUP on stdin or loses its X connection, -it kills the message bus daemon. + + + If this option is provided, a persistent "babysitter" process + will be created, and will connect to the X server. If it cannot + do so, launching fails. If the "babysitter" process loses its + X connection, it kills the message bus daemon, disconnecting + all of its clients (which should exit in response). This avoids + having leftover daemon processes from a user X session, after + the X session has ended. + + - + + + + + If this option is provided, a persistent "babysitter" process will + be created, as if for --exit-with-x11. If it cannot connect to + the X server, it will monitor the terminal from which dbus-launch + was started instead, and if it gets a HUP on stdin, the message + bus daemon will be killed. This option is not recommended, since + it will consume input from the terminal where it was started; + it is mainly provided for backwards compatibility. + + + diff --git a/tools/dbus-launch.c b/tools/dbus-launch.c index b2ffe41..b0d39bf 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] [--exit-with-x11]\n"); exit (ecode); } @@ -810,6 +810,7 @@ main (int argc, char **argv) const char *runprog = NULL; int remaining_args = 0; int exit_with_session; + int exit_with_x11 = FALSE; int binary_syntax = FALSE; int c_shell_syntax = FALSE; int bourne_shell_syntax = FALSE; @@ -851,6 +852,8 @@ main (int argc, char **argv) version (); else if (strcmp (arg, "--exit-with-session") == 0) exit_with_session = TRUE; + else if (strcmp (arg, "--exit-with-x11") == 0) + exit_with_x11 = TRUE; else if (strcmp (arg, "--close-stderr") == 0) close_stderr = TRUE; else if (strstr (arg, "--autolaunch=") == arg) @@ -962,6 +965,9 @@ main (int argc, char **argv) if (exit_with_session) verbose ("--exit-with-session enabled\n"); + if (exit_with_x11) + verbose ("--exit-with-x11 enabled\n"); + if (autolaunch) { #ifndef DBUS_BUILD_X11 @@ -984,10 +990,10 @@ main (int argc, char **argv) } verbose ("Autolaunch enabled (using X11).\n"); - if (!exit_with_session) + if (!exit_with_x11) { - verbose ("--exit-with-session automatically enabled\n"); - exit_with_session = TRUE; + verbose ("--exit-with-x11 automatically enabled\n"); + exit_with_x11 = TRUE; } if (!x11_init ()) @@ -1010,12 +1016,27 @@ main (int argc, char **argv) exit (0); } #endif /* DBUS_ENABLE_X11_AUTOLAUNCH */ +#endif /* DBUS_BUILD_X11 */ + } + else if (exit_with_x11) + { +#ifndef DBUS_BUILD_X11 + fprintf (stderr, "Session lifetime based on X11 requested, but X11 support not compiled in.\n"); + exit (1); +#else /* DBUS_BUILD_X11 */ + if (!x11_init ()) + { + fprintf (stderr, "Session lifetime based on X11 requested, but X11 initialization failed.\n"); + exit (1); + } +#endif /* DBUS_BUILD_X11 */ } +#ifdef DBUS_BUILD_X11 else if (read_machine_uuid_if_needed()) { x11_init(); -#endif /* DBUS_BUILD_X11 */ } +#endif /* DBUS_BUILD_X11 */ if (pipe (bus_pid_to_launcher_pipe) < 0 || @@ -1077,7 +1098,7 @@ main (int argc, char **argv) * and will also reap the pre-forked bus * daemon */ - babysit (exit_with_session, ret, + babysit (exit_with_session || exit_with_x11, ret, bus_pid_to_babysitter_pipe[READ_END]); exit (0); } -- 1.7.10.4