dbus/tools Makefile.am, 1.22, 1.23 dbus-cleanup-sockets.1, 1.2, 1.3 dbus-launch-x11.c, 1.1, 1.2 dbus-launch.c, 1.17, 1.18 dbus-uuidgen.1, NONE, 1.1 dbus-uuidgen.c, NONE, 1.1 run-with-tmp-session-bus.sh, 1.3, 1.4

Havoc Pennington hp at kemper.freedesktop.org
Sat Sep 30 20:18:49 PDT 2006


Update of /cvs/dbus/dbus/tools
In directory kemper:/tmp/cvs-serv15792/tools

Modified Files:
	Makefile.am dbus-cleanup-sockets.1 dbus-launch-x11.c 
	dbus-launch.c run-with-tmp-session-bus.sh 
Added Files:
	dbus-uuidgen.1 dbus-uuidgen.c 
Log Message:
2006-09-30  Havoc Pennington  <hp at redhat.com>

	* configure.in (LT_CURRENT, LT_AGE): increment current and age to
	reflect addition of interfaces.

	* doc/dbus-specification.xml: describe a new
	org.freedesktop.DBus.Peer.GetMachineId method

	* dbus/dbus-string.c (_dbus_string_skip_white_reverse): new function
	(_dbus_string_skip_white, _dbus_string_skip_blank): use new
	DBUS_IS_ASCII_BLANK, DBUS_IS_ASCII_WHITE macros and fix assertion
	at end of skip_white
	(_dbus_string_chop_white): new function

	* bus/connection.c (bus_connections_setup_connection): call
	dbus_connection_set_route_peer_messages.

	* dbus/dbus-connection.c
	(_dbus_connection_peer_filter_unlocked_no_update): modify to
	support a GetMachineId method.

	Also, support a new flag to let the bus pass peer methods through
	to apps on the bus, which can be set with
	dbus_connection_set_route_peer_messages.

	Finally, handle and return an error for anything unknown on the
	Peer interface, which will allow us to extend the Peer interface
	in the future without fear that we're now intercepting something
	apps were wanting to see.
	
	* tools/dbus-uuidgen.c: a thin wrapper around the functions in 
	dbus/dbus-uuidgen.c

	* dbus/dbus-uuidgen.c: implement the bulk of the dbus-uuidgen
	binary here, since most of the code is already in libdbus

	* dbus/dbus-sysdeps.c (_dbus_read_local_machine_uuid): read the
	uuid from the system config file

	* dbus/dbus-internals.c (_dbus_generate_uuid, _dbus_uuid_encode) 
	(_dbus_read_uuid_file_without_creating) 
	(_dbus_create_uuid_file_exclusively, _dbus_read_uuid_file): new
	uuid-related functions, partly factored out from dbus-server.c

	* dbus/dbus-sysdeps.c (_dbus_error_from_errno): convert EEXIST to
	DBUS_ERROR_FILE_EXISTS instead of EEXIST

	* dbus/dbus-protocol.h (DBUS_ERROR_FILE_EXISTS): add file exists error

	* tools/dbus-cleanup-sockets.1: explain what the point of this
	thing is a bit more

	* autogen.sh (run_configure): add --config-cache to default
	configure args

	* dbus/dbus-internals.h (_DBUS_ASSERT_ERROR_IS_SET): disable the
	error set/clear assertions when DBUS_DISABLE_CHECKS is defined

	* tools/dbus-launch.c (main): if xdisplay hasn't been opened,
	don't try to save address, fixes crash in make check



Index: Makefile.am
===================================================================
RCS file: /cvs/dbus/dbus/tools/Makefile.am,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- Makefile.am	30 Sep 2006 19:38:34 -0000	1.22
+++ Makefile.am	1 Oct 2006 03:18:47 -0000	1.23
@@ -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_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

Index: dbus-cleanup-sockets.1
===================================================================
RCS file: /cvs/dbus/dbus/tools/dbus-cleanup-sockets.1,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- dbus-cleanup-sockets.1	3 Aug 2006 20:34:36 -0000	1.2
+++ dbus-cleanup-sockets.1	1 Oct 2006 03:18:47 -0000	1.3
@@ -11,8 +11,8 @@
 
 .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 @@
 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.

Index: dbus-launch-x11.c
===================================================================
RCS file: /cvs/dbus/dbus/tools/dbus-launch-x11.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- dbus-launch-x11.c	30 Sep 2006 19:38:34 -0000	1.1
+++ dbus-launch-x11.c	1 Oct 2006 03:18:47 -0000	1.2
@@ -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;

Index: dbus-launch.c
===================================================================
RCS file: /cvs/dbus/dbus/tools/dbus-launch.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- dbus-launch.c	30 Sep 2006 19:38:34 -0000	1.17
+++ dbus-launch.c	1 Oct 2006 03:18:47 -0000	1.18
@@ -799,7 +799,7 @@
       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 @@
       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 */

--- NEW FILE: dbus-uuidgen.1 ---
.\" 
.\" 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/

--- NEW FILE: dbus-uuidgen.c ---
/* -*- 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);
    }
}

Index: run-with-tmp-session-bus.sh
===================================================================
RCS file: /cvs/dbus/dbus/tools/run-with-tmp-session-bus.sh,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- run-with-tmp-session-bus.sh	10 Aug 2006 21:44:00 -0000	1.3
+++ run-with-tmp-session-bus.sh	1 Oct 2006 03:18:47 -0000	1.4
@@ -34,7 +34,11 @@
 
 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 @@
 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



More information about the dbus-commit mailing list