dbus/dbus dbus-bus.c, 1.56, 1.57 dbus-connection.c, 1.133, 1.134 dbus-internals.h, 1.59, 1.60 dbus-sysdeps-unix.c, 1.5, 1.6 dbus-sysdeps.h, 1.59, 1.60 dbus-transport.c, 1.52, 1.53

Thiago J. Macieira thiago at kemper.freedesktop.org
Sat Sep 30 12:38:36 PDT 2006


Update of /cvs/dbus/dbus/dbus
In directory kemper:/tmp/cvs-serv22941/dbus

Modified Files:
	dbus-bus.c dbus-connection.c dbus-internals.h 
	dbus-sysdeps-unix.c dbus-sysdeps.h dbus-transport.c 
Log Message:
	* configure.in: add DBUS_BINDIR as a #define to C source code.

	* tools/dbus-launch.c
	* tools/dbus-launch.h
	* tools/dbus-launch-x11.c:
	* tools/dbus-launch.1: Add the --autolaunch option to
	dbus-launch, which makes it scan for an existing session
	started with --autolaunch. With that option, it also creates
	an X11 window and saves the bus address and PID to it.

	* dbus/dbus-sysdeps.h:
	* dbus/dbus-sysdeps-unix.c (_dbus_get_autolaunch_address): Add
	a function that runs "dbus-launch --autolaunch" to retrieve
	the running D-Bus session address (or start one if none was running)

	* dbus/dbus-transport.c: Add the handler for the "autolaunch:"
        address protocol, which tries to get the running session from
        dbus-launch.

	* dbus/dbus-bus.c:
	* dbus/dbus-internals.h: Make "autolaunch:" be the default
	D-Bus session bus address.

	* dbus/dbus-connection.c: Fix horrible typo in error message.


Index: dbus-bus.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-bus.c,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -d -r1.56 -r1.57
--- dbus-bus.c	16 Sep 2006 18:46:48 -0000	1.56
+++ dbus-bus.c	30 Sep 2006 19:38:34 -0000	1.57
@@ -175,6 +175,13 @@
           if (!get_from_env (&bus_connection_addresses[DBUS_BUS_SESSION],
                              "DBUS_SESSION_BUS_ADDRESS"))
             return FALSE;
+
+	  if (bus_connection_addresses[DBUS_BUS_SESSION] == NULL)
+	    bus_connection_addresses[DBUS_BUS_SESSION] =
+	      _dbus_strdup (DBUS_SESSION_BUS_DEFAULT_ADDRESS);
+           if (bus_connection_addresses[DBUS_BUS_SESSION] == NULL)
+             return FALSE;
+
           _dbus_verbose ("  \"%s\"\n", bus_connection_addresses[DBUS_BUS_SESSION] ?
                          bus_connection_addresses[DBUS_BUS_SESSION] : "none set");
         }

Index: dbus-connection.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-connection.c,v
retrieving revision 1.133
retrieving revision 1.134
diff -u -d -r1.133 -r1.134
--- dbus-connection.c	16 Sep 2006 18:46:48 -0000	1.133
+++ dbus-connection.c	30 Sep 2006 19:38:34 -0000	1.134
@@ -2783,7 +2783,7 @@
 
       error_msg = generate_local_error_message (client_serial,
                                                 DBUS_ERROR_DISCONNECTED, 
-                                                "Connection was dissconnected before a reply was recived"); 
+                                                "Connection was disconnected before a reply was received"); 
 
       /* on OOM error_msg is set to NULL */
       complete_pending_call_and_unlock (connection, pending, error_msg);

Index: dbus-internals.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-internals.h,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -d -r1.59 -r1.60
--- dbus-internals.h	16 Sep 2006 19:24:08 -0000	1.59
+++ dbus-internals.h	30 Sep 2006 19:38:34 -0000	1.60
@@ -37,6 +37,8 @@
 
 DBUS_BEGIN_DECLS
 
+#define DBUS_SESSION_BUS_DEFAULT_ADDRESS	"autolaunch:"
+
 void _dbus_warn               (const char *format,
                                ...) _DBUS_GNUC_PRINTF (1, 2);
 

Index: dbus-sysdeps-unix.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-sysdeps-unix.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- dbus-sysdeps-unix.c	16 Sep 2006 15:49:27 -0000	1.5
+++ dbus-sysdeps-unix.c	30 Sep 2006 19:38:34 -0000	1.6
@@ -27,6 +27,7 @@
 #include "dbus-sysdeps-unix.h"
 #include "dbus-threads.h"
 #include "dbus-protocol.h"
+#include "dbus-transport.h"
 #include "dbus-string.h"
 #include <sys/types.h>
 #include <stdlib.h>
@@ -2275,6 +2276,118 @@
   return tmpdir;
 }
 
+/**
+ * Determines the address of the session bus by querying a
+ * platform-specific method.
+ *
+ * If successful, returns #TRUE and appends the address to @p
+ * address. If a failure happens, returns #FALSE and
+ * sets an error in @p error.
+ *
+ * @param address a DBusString where the address can be stored
+ * @param error a DBusError to store the error in case of failure
+ * @returns #TRUE on success, #FALSE if an error happened
+ */
+dbus_bool_t
+_dbus_get_autolaunch_address (DBusString *address, DBusError *error)
+{
+  static char *argv[] = { DBUS_BINDIR "/dbus-launch", "--autolaunch",
+                          "--binary-syntax", NULL };
+  int address_pipe[2];
+  pid_t pid;
+  int ret;
+  int status;
+  int orig_len = _dbus_string_get_length (address);
+
+  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
+
+#define READ_END        0
+#define WRITE_END       1
+  if (pipe (address_pipe) < 0)
+    {
+      dbus_set_error (error, _dbus_error_from_errno (errno),
+                      "Failed to create a pipe: %s",
+                      _dbus_strerror (errno));
+      _dbus_verbose ("Failed to create a pipe to call dbus-launch: %s\n",
+                     _dbus_strerror (errno));
+      return FALSE;
+    }
+
+  pid = fork ();
+  if (pid < 0)
+    {
+      dbus_set_error (error, _dbus_error_from_errno (errno),
+                      "Failed to fork(): %s",
+                      _dbus_strerror (errno));
+      _dbus_verbose ("Failed to fork() to call dbus-launch: %s\n",
+                     _dbus_strerror (errno));
+      return FALSE;
+    }
+
+  if (pid == 0)
+    {
+      /* child process */
+      int fd = open ("/dev/null", O_RDWR);
+      if (fd == -1)
+        /* huh?! can't open /dev/null? */
+        _exit (1);
+
+      /* set-up stdXXX */
+      close (address_pipe[READ_END]);
+      close (0);                /* close stdin */
+      close (1);                /* close stdout */
+      close (2);                /* close stderr */
+
+      if (dup2 (fd, 0) == -1)
+        _exit (1);
+      if (dup2 (address_pipe[WRITE_END], 1) == -1)
+        _exit (1);
+      if (dup2 (fd, 2) == -1)
+        _exit (1);
+
+      close (fd);
+      close (address_pipe[WRITE_END]);
+
+      execv (argv[0], argv);
+
+      /* failed, try searching PATH */
+      argv[0] = "dbus-launch";
+      execvp ("dbus-launch", argv);
+
+      /* still nothing, we failed */
+      _exit (1);
+    }
+
+  /* parent process */
+  close (address_pipe[WRITE_END]);
+  ret = 0;
+  do 
+    {
+      ret = _dbus_read (address_pipe[READ_END], address, 1024);
+    }
+  while (ret > 0);
+
+  /* reap the child process to avoid it lingering as zombie */
+  do
+    {
+      ret = waitpid (pid, &status, 0);
+    }
+  while (ret == -1 && errno == EINTR);
+
+  /* We succeeded if the process exited with status 0 and
+     anything was read */
+  if (!WIFEXITED (status) || WEXITSTATUS (status) != 0 ||
+      _dbus_string_get_length (address) == orig_len)
+    {
+      /* The process ended with error */
+      _dbus_string_set_length (address, orig_len);
+      dbus_set_error (error, DBUS_ERROR_SPAWN_EXEC_FAILED,
+                      "Failed to execute dbus-launch to autolaunch D-Bus session");
+      return FALSE;
+    }
+  return TRUE;
+}
+
 /** @} end of sysdeps */
 
 /* tests in dbus-sysdeps-util.c */

Index: dbus-sysdeps.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-sysdeps.h,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -d -r1.59 -r1.60
--- dbus-sysdeps.h	16 Sep 2006 17:38:24 -0000	1.59
+++ dbus-sysdeps.h	30 Sep 2006 19:38:34 -0000	1.60
@@ -376,6 +376,9 @@
 dbus_bool_t _dbus_parse_uid (const DBusString  *uid_str,
                              dbus_uid_t        *uid);
 
+dbus_bool_t _dbus_get_autolaunch_address (DBusString *address, 
+					  DBusError *error);
+
 DBUS_END_DECLS
 
 #endif /* DBUS_SYSDEPS_H */

Index: dbus-transport.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-transport.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -d -r1.52 -r1.53
--- dbus-transport.c	17 Sep 2006 17:11:31 -0000	1.52
+++ dbus-transport.c	30 Sep 2006 19:38:34 -0000	1.53
@@ -201,13 +201,118 @@
   dbus_free (transport->expected_guid);
 }
 
+
+/**
+ * Verifies if a given D-Bus address is a valid address
+ * by attempting to connect to it. If it is, returns the
+ * opened DBusTransport object. If it isn't, returns #NULL
+ * and sets @p error.
+ *
+ * @param error address where an error can be returned.
+ * @returns a new transport, or #NULL on failure.
+ */
+static DBusTransport*
+check_address (const char *address, DBusError *error)
+{
+  DBusAddressEntry **entries;
+  DBusTransport *transport = NULL;
+  int len, i;
+
+  _dbus_assert (address != NULL);
+  _dbus_assert (*address != '\0');
+
+  if (!dbus_parse_address (address, &entries, &len, error))
+    return FALSE;              /* not a valid address */
+
+  for (i = 0; i < len; i++)
+    {
+      transport = _dbus_transport_open (entries[i], error);
+      if (transport != NULL)
+        break;
+    }
+
+  dbus_address_entries_free (entries);
+  return transport;
+}
+
+/**
+ * Creates a new transport for the "autostart" method.
+ * This creates a client-side of a transport.
+ *
+ * @param error address where an error can be returned.
+ * @returns a new transport, or #NULL on failure.
+ */
+static DBusTransport*
+_dbus_transport_new_for_autolaunch (DBusError      *error)
+{
+  DBusString address;
+  DBusTransport *result = NULL;
+
+  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
+
+  if (!_dbus_string_init (&address))
+    {
+      dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+      return NULL;
+    }
+
+  if (!_dbus_get_autolaunch_address (&address, error))
+    {
+      _DBUS_ASSERT_ERROR_IS_SET (error);
+      goto out;
+    }
+
+  result = check_address (_dbus_string_get_const_data (&address), error);
+  if (result == NULL)
+    _DBUS_ASSERT_ERROR_IS_SET (error);
+  else
+    _DBUS_ASSERT_ERROR_IS_CLEAR (error);
+
+ out:
+  _dbus_string_free (&address);
+  return result;
+}
+
+static DBusTransportOpenResult
+_dbus_transport_open_autolaunch (DBusAddressEntry  *entry,
+                                 DBusTransport    **transport_p,
+                                 DBusError         *error)
+{
+  const char *method;
+  
+  method = dbus_address_entry_get_method (entry);
+  _dbus_assert (method != NULL);
+
+  if (strcmp (method, "autolaunch") == 0)
+    {
+      *transport_p = _dbus_transport_new_for_autolaunch (error);
+
+      if (*transport_p == NULL)
+        {
+          _DBUS_ASSERT_ERROR_IS_SET (error);
+          return DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT;
+        }
+      else
+        {
+          _DBUS_ASSERT_ERROR_IS_CLEAR (error);
+          return DBUS_TRANSPORT_OPEN_OK;
+        }      
+    }
+  else
+    {
+      _DBUS_ASSERT_ERROR_IS_CLEAR (error);
+      return DBUS_TRANSPORT_OPEN_NOT_HANDLED;
+    }
+}
+
 static const struct {
   DBusTransportOpenResult (* func) (DBusAddressEntry *entry,
                                     DBusTransport   **transport_p,
                                     DBusError        *error);
 } open_funcs[] = {
   { _dbus_transport_open_socket },
-  { _dbus_transport_open_platform_specific }
+  { _dbus_transport_open_platform_specific },
+  { _dbus_transport_open_autolaunch }
 #ifdef DBUS_BUILD_TESTS
   , { _dbus_transport_open_debug_pipe }
 #endif



More information about the dbus-commit mailing list