diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/Makefile.am | 8 | ||||
-rw-r--r-- | tools/dbus-cleanup-sockets.1 | 17 | ||||
-rw-r--r-- | tools/dbus-launch-x11.c | 2 | ||||
-rw-r--r-- | tools/dbus-launch.c | 59 | ||||
-rw-r--r-- | tools/dbus-uuidgen.1 | 91 | ||||
-rw-r--r-- | tools/dbus-uuidgen.c | 161 | ||||
-rwxr-xr-x | tools/run-with-tmp-session-bus.sh | 8 |
7 files changed, 311 insertions, 35 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am index 05c3618e..a3d786c4 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -1,6 +1,6 @@ INCLUDES=-I$(top_srcdir) $(DBUS_CLIENT_CFLAGS) $(DBUS_X_CFLAGS) -DDBUS_LOCALEDIR=\"@EXPANDED_DATADIR@/locale\" -DDBUS_COMPILATION -DDBUS_DAEMONDIR=\"@DBUS_DAEMONDIR@\" -bin_PROGRAMS=dbus-send dbus-monitor dbus-launch dbus-cleanup-sockets +bin_PROGRAMS=dbus-send dbus-monitor dbus-launch dbus-cleanup-sockets dbus-uuidgen dbus_send_SOURCES= \ dbus-print-message.c \ @@ -19,11 +19,15 @@ dbus_launch_SOURCES= \ dbus_cleanup_sockets_SOURCES= \ dbus-cleanup-sockets.c +dbus_uuidgen_SOURCES= \ + dbus-uuidgen.c + dbus_send_LDADD= $(top_builddir)/dbus/libdbus-1.la dbus_monitor_LDADD= $(top_builddir)/dbus/libdbus-1.la +dbus_uuidgen_LDADD= $(top_builddir)/dbus/libdbus-1.la dbus_launch_LDADD= $(DBUS_X_LIBS) -man_MANS = dbus-send.1 dbus-monitor.1 dbus-launch.1 dbus-cleanup-sockets.1 +man_MANS = dbus-send.1 dbus-monitor.1 dbus-launch.1 dbus-cleanup-sockets.1 dbus-uuidgen.1 EXTRA_DIST = $(man_MANS) run-with-tmp-session-bus.sh CLEANFILES = \ run-with-tmp-session-bus.conf diff --git a/tools/dbus-cleanup-sockets.1 b/tools/dbus-cleanup-sockets.1 index e093ab0f..ca669f49 100644 --- a/tools/dbus-cleanup-sockets.1 +++ b/tools/dbus-cleanup-sockets.1 @@ -11,8 +11,8 @@ dbus-cleanup-sockets \- clean up leftover sockets in a directory .SH DESCRIPTION -The \fIdbus-cleanup-sockets\fP command cleans up sockets used for -D-Bus connections. See http://www.freedesktop.org/software/dbus/ for +The \fIdbus-cleanup-sockets\fP command cleans up unused D-Bus +connection sockets. See http://www.freedesktop.org/software/dbus/ for more information about the big picture. .PP @@ -21,6 +21,19 @@ in the standard default socket directory for the per-user-login-session message bus; this is usually /tmp. Optionally, you can pass a different directory on the command line. +.PP +On Linux, this program is essentially useless, because D-Bus defaults +to using "abstract sockets" that exist only in memory and don't have a +corresponding file in /tmp. + +.PP +On most other flavors of UNIX, it's possible for the socket files to +leak when programs using D-Bus exit abnormally or without closing +their D-Bus connections. Thus, it might be interesting to run +dbus-cleanup-sockets in a cron job to mop up any leaked sockets. +Or you can just ignore the leaked sockets, they aren't really hurting +anything, other than cluttering the output of "ls /tmp" + .SH AUTHOR dbus-cleanup-sockets was adapted by Havoc Pennington from linc-cleanup-sockets written by Michael Meeks. diff --git a/tools/dbus-launch-x11.c b/tools/dbus-launch-x11.c index ac356219..67aef04d 100644 --- a/tools/dbus-launch-x11.c +++ b/tools/dbus-launch-x11.c @@ -33,7 +33,7 @@ #include <X11/Xlib.h> #include <X11/Xatom.h> -Display *xdisplay; +Display *xdisplay = NULL; static Atom selection_atom; static Atom address_atom; static Atom pid_atom; diff --git a/tools/dbus-launch.c b/tools/dbus-launch.c index fb993e4e..1589c168 100644 --- a/tools/dbus-launch.c +++ b/tools/dbus-launch.c @@ -799,7 +799,7 @@ main (int argc, char **argv) fprintf (stderr, "Failed to execute message bus daemon %s: %s. Will try again without full path.\n", DBUS_DAEMONDIR"/dbus-daemon", strerror (errno)); - + /* * If it failed, try running without full PATH. Note this is needed * because the build process builds the run-with-tmp-session-bus.conf @@ -902,33 +902,36 @@ main (int argc, char **argv) close (bus_pid_to_launcher_pipe[READ_END]); #ifdef DBUS_BUILD_X11 - ret2 = x11_save_address (bus_address, bus_pid, &wid); - if (ret2 == 0) - { - /* another window got added. Return its address */ - char *address; - pid_t pid; - long wid; - - if (x11_get_address (&address, &pid, &wid) && 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); - free (address); - - bus_pid_to_kill = bus_pid; - kill_bus_and_exit (0); - } - - /* if failed, fall through */ - } - if (ret2 <= 0) - { - fprintf (stderr, "Error saving bus information.\n"); - bus_pid_to_kill = bus_pid; - kill_bus_and_exit (1); - } + if (xdisplay != NULL) + { + ret2 = x11_save_address (bus_address, bus_pid, &wid); + if (ret2 == 0) + { + /* another window got added. Return its address */ + char *address; + pid_t pid; + long wid; + + if (x11_get_address (&address, &pid, &wid) && 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); + free (address); + + bus_pid_to_kill = bus_pid; + kill_bus_and_exit (0); + } + + /* if failed, fall through */ + } + if (ret2 <= 0) + { + fprintf (stderr, "Error saving bus information.\n"); + bus_pid_to_kill = bus_pid; + kill_bus_and_exit (1); + } + } #endif /* Forward the pid to the babysitter */ diff --git a/tools/dbus-uuidgen.1 b/tools/dbus-uuidgen.1 new file mode 100644 index 00000000..7b533723 --- /dev/null +++ b/tools/dbus-uuidgen.1 @@ -0,0 +1,91 @@ +.\" +.\" dbus-uuidgen manual page. +.\" Copyright (C) 2006 Red Hat, Inc. +.\" +.TH dbus-uuidgen 1 +.SH NAME +dbus-uuidgen \- Utility to generate UUIDs +.SH SYNOPSIS +.PP +.B dbus-uuidgen [\-\-version] [\-\-ensure[=FILENAME]] [\-\-get[=FILENAME]] + +.SH DESCRIPTION + +The \fIdbus-uuidgen\fP command generates or reads a universally unique ID. + +.PP +See http://www.freedesktop.org/software/dbus/ for more information +about D-Bus. + +.PP +The primary usage of \fIdbus-uuidgen\fP is to run in the post-install +script of a D-Bus package like this: +.nf + dbus-uuidgen --ensure +.fi + +.PP +This will ensure that /etc/dbus-1/machine-id exists and has the uuid in it. +It won't overwrite an existing uuid, since this id should remain fixed +for a single machine until the next reboot at least. + +.PP +The important properties of the machine UUID are that 1) it remains +unchanged until the next reboot and 2) it is different for any two +running instances of the OS kernel. That is, if two processes see the +same UUID, they should also see the same shared memory, UNIX domain +sockets, local X displays, localhost.localdomain resolution, process +IDs, and so forth. + +.PP +If you run \fIdbus-uuidgen\fP with no options it just prints a new uuid made +up out of thin air. This is similar to the regular "uuidgen" command. + +.PP +If you run it with --get, it prints the machine uuid by default, or +the uuid in the specified file if you specify a file. + +.PP +The D-Bus UUID has no relationship to RFC 4122 and does not generate +UUIDs compatible with that spec. + +.PP +If you try to change an existing /etc/dbus-1/machine-id on a running +system, it will probably result in bad things happening. Don't try +to change this file. Also, don't make it the same on two different +systems; it needs to be different anytime there are two different +kernels running. + +.PP +If you need to share /etc between two different kernels, a possible solution +is to symlink the machine ID to /var, and run "dbus-uuidgen +--ensure=/var/whatever" from an early boot script or the system +message bus boot script. + +.SH OPTIONS +The following options are supported: +.TP +.I "--get[=FILENAME]" +If a filename is not given, defaults to sysconfdir/dbus-1/machine-id +(sysconfdir is usually /etc). If this file exists and is valid, the +uuid in the file is printed on stdout. Otherwise, the command exits +with a nonzero status. + +.TP +.I "--ensure[=FILENAME]" +If a filename is not given, defaults to sysconfdir/dbus-1/machine-id +(sysconfdir is usually /etc). If this file exists then it will be +validated, and a failure code returned if it contains the wrong thing. +If the file does not exist, it will be created with a new uuid in it. +On success, prints no output. + +.TP +.I "--version" +Print the version of dbus-uuidgen + +.SH AUTHOR +See http://www.freedesktop.org/software/dbus/doc/AUTHORS + +.SH BUGS +Please send bug reports to the D-Bus mailing list or bug tracker, +see http://www.freedesktop.org/software/dbus/ diff --git a/tools/dbus-uuidgen.c b/tools/dbus-uuidgen.c new file mode 100644 index 00000000..569bdb07 --- /dev/null +++ b/tools/dbus-uuidgen.c @@ -0,0 +1,161 @@ +/* -*- mode: C; c-file-style: "gnu" -*- */ +/* dbus-uuidgen.c Utility program to create UUIDs + * + * Copyright (C) 2006 Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include <config.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <dbus/dbus-uuidgen.h> +#include <dbus/dbus.h> + +static void +usage (char *name, int ecode) +{ + if (name == NULL) + name = "dbus-uuidgen"; + + fprintf (stderr, "Usage: %s [--ensure[=FILENAME]] [--get[=FILENAME]]\n", name); + exit (ecode); +} + +static void +version (void) +{ + printf ("D-Bus UUID Generator %s\n" + "Copyright (C) 2006 Red Hat, Inc.\n" + "This is free software; see the source for copying conditions.\n" + "There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n", + VERSION); + exit (0); +} + +static dbus_bool_t +get_arg (const char *arg, + const char *option, + const char **value_p) +{ + const char *fn; + + if (strlen(arg) < strlen(option)) + return FALSE; + + fn = arg + strlen(option); + + if (!(*fn == '=' || *fn == ' ' || *fn == '\0')) + { + usage (NULL, 1); + } + + if (*fn == '=') + ++fn; + + while (*fn == ' ' && *fn != '\0') + ++fn; + + if (*fn != '\0') + { + *value_p = fn; + return TRUE; + } + + return FALSE; +} + +int +main (int argc, char *argv[]) +{ + int i; + const char *filename; + dbus_bool_t ensure_uuid; + dbus_bool_t get_uuid; + DBusError error; + + ensure_uuid = FALSE; + get_uuid = FALSE; + + filename = NULL; + + for (i = 1; i < argc; i++) + { + char *arg = argv[i]; + + if (strncmp (arg, "--ensure", strlen("--ensure")) == 0) + { + get_arg (arg, "--ensure", &filename); + ensure_uuid = TRUE; + } + else if (strncmp (arg, "--get", strlen("--get")) == 0) + { + get_arg (arg, "--get", &filename); + get_uuid = TRUE; + } + else if (strcmp (arg, "--help") == 0) + usage (argv[0], 0); + else if (strcmp (arg, "--version") == 0) + version (); + else + usage (argv[0], 1); + } + + if (get_uuid && ensure_uuid) + { + fprintf (stderr, "Can't specify both --get and --ensure\n"); + exit (1); + } + + dbus_error_init (&error); + + if (get_uuid || ensure_uuid) + { + char *uuid; + if (dbus_internal_do_not_use_get_uuid (filename, &uuid, ensure_uuid, &error)) + { + if (get_uuid) /* print nothing on --ensure */ + printf ("%s\n", uuid); + dbus_free (uuid); + } + } + else + { + char *uuid; + if (dbus_internal_do_not_use_create_uuid (&uuid)) + { + printf ("%s\n", uuid); + dbus_free (uuid); + } + else + { + dbus_set_error (&error, DBUS_ERROR_NO_MEMORY, "No memory"); + } + } + + if (dbus_error_is_set (&error)) + { + fprintf (stderr, "%s\n", error.message); + dbus_error_free (&error); + exit (1); + } + else + { + exit (0); + } +} diff --git a/tools/run-with-tmp-session-bus.sh b/tools/run-with-tmp-session-bus.sh index 880924b7..b72a56a5 100755 --- a/tools/run-with-tmp-session-bus.sh +++ b/tools/run-with-tmp-session-bus.sh @@ -34,7 +34,11 @@ cat $DBUS_TOP_BUILDDIR/bus/session.conf | \ echo "Created configuration file $CONFIG_FILE" >&2 -export PATH=$DBUS_TOP_BUILDDIR/bus:$PATH +if ! test -e "$DBUS_TOP_BUILDDIR"/bus/dbus-daemon ; then + die "$DBUS_TOP_BUILDDIR/bus/dbus-daemon does not exist" +fi + +export PATH="$DBUS_TOP_BUILDDIR"/bus:$PATH ## the libtool script found by the path search should already do this, but export LD_LIBRARY_PATH=$DBUS_TOP_BUILDDIR/dbus/.libs:$LD_LIBRARY_PATH @@ -46,7 +50,7 @@ echo "Running $DBUS_TOP_BUILDDIR/tools/dbus-launch --sh-syntax --config-file=$CO eval `$DBUS_TOP_BUILDDIR/tools/dbus-launch --sh-syntax --config-file=$CONFIG_FILE` if test -z "$DBUS_SESSION_BUS_PID" ; then - die "Failed to launch message bus for introspection generation to run" + die "Failed to launch message bus for test script to run" fi echo "Started bus pid $DBUS_SESSION_BUS_PID at $DBUS_SESSION_BUS_ADDRESS" >&2 |