From 10fe37f58213d3895229208453c3e691e554ed72 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Sun, 1 Oct 2006 20:05:39 +0000 Subject: 2006-10-01 Havoc Pennington * tools/dbus-launch.c (print_variables): if no syntax is given, don't print something that's sort-of-half-sh-syntax, just print a plain key-value pairs thing. * tools/dbus-launch-x11.c: use machine ID rather than hostname for the local machine representation (but still have the hostname in the display). Remove the hostname from the display if it is localhost. Change session files to be named ~/.dbus/session-bus/machine-display. Change X atoms to be underscore-prefixed so nobody whines about ICCCM compliance. Otherwise name them the same as the env variables. Change session file format to include key-value pairs and an explanatory comment. Keys are the same as the env variables. (set_address_in_x11): X property format can't depend on sizeof(pid_t) on a particular machine, fix to always be 32 bits * tools/dbus-launch.c: make --autolaunch take a machine id argument. If --autolaunch is used with a program to run, complain for now (but add a FIXME). Also, don't look for existing bus if there's a program to run (but add a FIXME). * dbus/dbus-sysdeps-unix.c (_dbus_get_autolaunch_address): pass machine uuid to dbus-launch (avoids linking dbus-launch to libdbus just to get this, and avoids duplicating uuid-reading code). * tools/dbus-launch.1: clarify various things --- tools/dbus-launch.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 87 insertions(+), 6 deletions(-) (limited to 'tools/dbus-launch.c') diff --git a/tools/dbus-launch.c b/tools/dbus-launch.c index 1589c168..c743121b 100644 --- a/tools/dbus-launch.c +++ b/tools/dbus-launch.c @@ -1,7 +1,8 @@ /* -*- mode: C; c-file-style: "gnu" -*- */ /* dbus-launch.c dbus-launch utility * - * Copyright (C) 2003 Red Hat, Inc. + * Copyright (C) 2003, 2006 Red Hat, Inc. + * Copyright (C) 2006 Thiago Macieira * * Licensed under the Academic Free License version 2.1 * @@ -39,6 +40,27 @@ extern Display *xdisplay; #endif +static char* machine_uuid = NULL; + +const char* +get_machine_uuid (void) +{ + return machine_uuid; +} + +static void +save_machine_uuid (const char *uuid_arg) +{ + if (strlen (uuid_arg) != 32) + { + fprintf (stderr, "machine ID '%s' looks like it's the wrong length, should be 32 hex digits", + uuid_arg); + exit (1); + } + + machine_uuid = xstrdup (uuid_arg); +} + void verbose (const char *format, ...) @@ -303,8 +325,9 @@ print_variables (const char *bus_address, pid_t bus_pid, long bus_wid, printf ("set DBUS_SESSION_BUS_PID=%ld;\n", (long) bus_pid); if (bus_wid) printf ("set DBUS_SESSION_BUS_WINDOWID=%ld;\n", (long) bus_wid); + fflush (stdout); } - else + else if (bourne_shell_syntax) { printf ("DBUS_SESSION_BUS_ADDRESS='%s';\n", bus_address); if (bourne_shell_syntax) @@ -312,6 +335,15 @@ print_variables (const char *bus_address, pid_t bus_pid, long bus_wid, printf ("DBUS_SESSION_BUS_PID=%ld;\n", (long) bus_pid); if (bus_wid) printf ("DBUS_SESSION_BUS_WINDOWID=%ld;\n", (long) bus_wid); + fflush (stdout); + } + else + { + printf ("DBUS_SESSION_BUS_ADDRESS=%s\n", bus_address); + printf ("DBUS_SESSION_BUS_PID=%ld\n", (long) bus_pid); + if (bus_wid) + printf ("DBUS_SESSION_BUS_WINDOWID=%ld\n", (long) bus_wid); + fflush (stdout); } } @@ -614,8 +646,38 @@ main (int argc, char **argv) version (); else if (strcmp (arg, "--exit-with-session") == 0) exit_with_session = TRUE; + else if (strstr (arg, "--autolaunch=") == arg) + { + const char *s; + + if (autolaunch) + { + fprintf (stderr, "--autolaunch given twice\n"); + exit (1); + } + + autolaunch = TRUE; + + s = strchr (arg, '='); + ++s; + + save_machine_uuid (s); + } + else if (prev_arg && + strcmp (prev_arg, "--autolaunch") == 0) + { + if (autolaunch) + { + fprintf (stderr, "--autolaunch given twice\n"); + exit (1); + } + + autolaunch = TRUE; + + save_machine_uuid (arg); + } else if (strcmp (arg, "--autolaunch") == 0) - autolaunch = TRUE; + ; /* wait for next arg */ else if (strstr (arg, "--config-file=") == arg) { const char *file; @@ -673,7 +735,7 @@ main (int argc, char **argv) verbose ("--exit-with-session enabled\n"); if (autolaunch) - { + { #ifndef DBUS_BUILD_X11 fprintf (stderr, "Autolaunch requested, but X11 support not compiled in.\n" "Cannot continue.\n"); @@ -682,7 +744,23 @@ main (int argc, char **argv) char *address; pid_t pid; long wid; + + if (get_machine_uuid () == NULL) + { + fprintf (stderr, "Machine UUID not provided as arg to --autolaunch\n"); + exit (1); + } + /* FIXME right now autolaunch always does print_variables(), but it should really + * exec the child program instead if a child program was specified. For now + * we just exit if this conflict arises. + */ + if (runprog) + { + fprintf (stderr, "Currently --autolaunch does not support running a program\n"); + exit (1); + } + verbose ("Autolaunch enabled (using X11).\n"); if (!exit_with_session) { @@ -703,7 +781,7 @@ main (int argc, char **argv) } if (address != NULL) - { + { verbose ("dbus-daemon is already running. Returning existing parameters.\n"); print_variables (address, pid, wid, c_shell_syntax, bourne_shell_syntax, binary_syntax); @@ -902,7 +980,10 @@ main (int argc, char **argv) close (bus_pid_to_launcher_pipe[READ_END]); #ifdef DBUS_BUILD_X11 - if (xdisplay != NULL) + /* FIXME the runprog == NULL is broken - we need to launch the runprog with the existing bus, + * instead of just doing print_variables() if there's an existing bus. + */ + if (xdisplay != NULL && runprog == NULL) { ret2 = x11_save_address (bus_address, bus_pid, &wid); if (ret2 == 0) -- cgit