summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <smcv@debian.org>2016-07-11 12:10:39 +0100
committerSimon McVittie <smcv@debian.org>2016-07-11 12:10:39 +0100
commit7d0a16dead07b4a683a4f3ef7658cd77c843b65f (patch)
tree7aff998e8228ce19db7998d26ff06449cd1da3b6
parentb36708830b8a0e5c1166a882cba5bbe7afa966ca (diff)
dbus-launch: add --exit-with-x11 optionHEADmaster
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. We read the machine UUID because it is needed to set the X atoms. x11_init() assumes that the machine UUID (global variable) has been set, either via read_machine_uuid_if_needed() or save_machine_uuid(). This is pretty tangled, but to make The Right Thing happen automatically, we'd need to redo dbus-launch in terms of DBusError. Reviewed-by: Will Thompson Reviewed-by: Thiago Macieira Bug: https://bugs.freedesktop.org/show_bug.cgi?id=39197 Signed-off-by: Simon McVittie <smcv@debian.org>
-rw-r--r--doc/dbus-launch.1.xml.in34
-rw-r--r--tools/dbus-launch.c39
2 files changed, 60 insertions, 13 deletions
diff --git a/doc/dbus-launch.1.xml.in b/doc/dbus-launch.1.xml.in
index 5135d9ca..2fcea03f 100644
--- a/doc/dbus-launch.1.xml.in
+++ b/doc/dbus-launch.1.xml.in
@@ -29,6 +29,7 @@
<arg choice='opt'>--binary-syntax </arg>
<arg choice='opt'>--close-stderr </arg>
<arg choice='opt'>--exit-with-session </arg>
+ <arg choice='opt'>--exit-with-x11 </arg>
<arg choice='opt'>--autolaunch=<replaceable>MACHINEID</replaceable></arg>
<arg choice='opt'>--config-file=<replaceable>FILENAME</replaceable></arg>
<arg choice='opt'><replaceable>PROGRAM</replaceable></arg>
@@ -216,16 +217,35 @@ the --session argument. See the man page for dbus-daemon</para>
</listitem>
</varlistentry>
+
<varlistentry>
- <term><option>--exit-with-session</option></term>
- <listitem>
-<para>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.</para>
+ <term><option>--exit-with-x11</option></term>
+ <listitem>
+ <para>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.</para>
+ </listitem>
+ </varlistentry>
- </listitem>
+ <varlistentry>
+ <term><option>--exit-with-session</option></term>
+ <listitem>
+ <para>
+ 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.
+ </para>
+ </listitem>
</varlistentry>
+
<varlistentry>
<term><option>--autolaunch=MACHINEID</option></term>
<listitem>
diff --git a/tools/dbus-launch.c b/tools/dbus-launch.c
index 1b655027..800c1123 100644
--- a/tools/dbus-launch.c
+++ b/tools/dbus-launch.c
@@ -169,7 +169,7 @@ usage (int ecode)
{
fprintf (stderr, "dbus-launch [--version] [--help] [--sh-syntax]"
" [--csh-syntax] [--auto-syntax] [--binary-syntax] [--close-stderr]"
- " [--exit-with-session] [--autolaunch=MACHINEID]"
+ " [--exit-with-session|--exit-with-x11] [--autolaunch=MACHINEID]"
" [--config-file=FILENAME] [PROGRAM] [ARGS...]\n");
exit (ecode);
}
@@ -827,6 +827,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;
@@ -870,6 +871,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)
@@ -981,6 +984,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
@@ -1035,10 +1041,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 ())
@@ -1061,12 +1067,33 @@ 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 (!read_machine_uuid_if_needed())
+ {
+ fprintf (stderr, "Session lifetime based on X11 requested, but machine UUID unavailable.\n");
+ exit (1);
+ }
+
+ 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 ||
@@ -1128,7 +1155,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);
}