--- save/dbus-server-launchd.c	2009-01-17 12:18:29.000000000 -0500
+++ dbus/dbus-server-launchd.c	2009-01-17 22:19:21.000000000 -0500
@@ -29,6 +29,8 @@
 
 #include "dbus-server-socket.h"
 #include "dbus-server-launchd.h"
+#include "dbus-transport-protected.h"
+#include "dbus-transport-unix.h"
 
 /**
  * @defgroup DBusServerLaunchd DBusServer implementations for Launchd
@@ -56,6 +58,7 @@
   launch_data_t sockets_dict, checkin_response;
   launch_data_t checkin_request;
   launch_data_t listening_fd_array, listening_fd;
+  dbus_bool_t supported, retval;
 
   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
 
@@ -64,14 +67,21 @@
       dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
       return NULL;
     }
-  if (!_dbus_string_append (&address, "launchd:key="))
+  
+  if (strcmp (socket_key, "session") != 0)
     {
-      dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+      dbus_set_error (error, DBUS_ERROR_FAILED, "Not server socket %s\n", socket_key);
       goto l_failed_0;
     }
-  if (!_dbus_string_append (&address, socket_key))
+  supported = FALSE;
+  retval = _dbus_lookup_session_address (&supported, &address, error);
+  if ( !(supported && retval) )
     {
-      dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+      if (!dbus_error_is_set(error))
+        {
+          dbus_set_error(error, DBUS_ERROR_FAILED,
+                         "Unable to get session socket address\n");
+        }
       goto l_failed_0;
     }
 
@@ -146,5 +156,99 @@
   return NULL;
 }
 
+/**
+ * Opens launchd transport types.
+ * 
+ * @param entry the address entry to try opening
+ * @param transport_p return location for the opened transport
+ * @param error error to be set
+ * @returns result of the attempt
+ */
+DBusTransportOpenResult
+_dbus_transport_open_launchd (DBusAddressEntry  *entry,
+                              DBusTransport    **transport_p,
+                              DBusError         *error)
+{
+  const char *method, *path;
+  
+  method = dbus_address_entry_get_method (entry);
+  _dbus_assert (method != NULL);
+
+  if (strcmp (method, "launchd") == 0)
+    {
+      const char *socket_key = dbus_address_entry_get_value (entry, "key");
+      DBusString address, prefix;
+      dbus_bool_t supported, retval;
+      int prefixlen;
+      
+      _dbus_verbose ("Opening launchd transport\n");
+
+      if (socket_key == NULL)
+        {
+          _dbus_set_bad_address (error, "launchd", "key", NULL);
+          return DBUS_TRANSPORT_OPEN_BAD_ADDRESS;
+        }
+      
+      if (strcmp (socket_key, "session") != 0)
+        {
+          _dbus_set_bad_address (error, NULL, NULL,
+                                 "launchd key must be 'session'\n");
+          return DBUS_TRANSPORT_OPEN_BAD_ADDRESS;
+        }
+      
+      if (!_dbus_string_init (&address))
+        {
+          dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+          return DBUS_TRANSPORT_OPEN_BAD_ADDRESS;
+        }
+  
+      supported = FALSE;
+      retval = _dbus_lookup_session_address (&supported, &address, error);
+      _dbus_string_init_const (&prefix, "unix:path=");
+      prefixlen = _dbus_string_get_length(&prefix);
+      if ( !(supported && retval) ||
+           !_dbus_string_equal_substring (&address, 0, prefixlen, &prefix, 0))
+        {
+          if (!dbus_error_is_set(error))
+            {
+              dbus_set_error(error, DBUS_ERROR_FAILED,
+                             "Unable to get session socket address\n");
+            }
+          goto l_failed_1;
+        }
+      path = _dbus_string_get_const_data_len ( &address, prefixlen, 
+                                               _dbus_string_get_length( &address) - prefixlen );
+      *transport_p = _dbus_transport_new_for_domain_socket ( path, FALSE, error );
+      
+      if (*transport_p == NULL)
+        {
+          _DBUS_ASSERT_ERROR_IS_SET (error);
+          goto l_failed_1;
+        }
+      
+      _dbus_verbose ("Opened launchd socket at %s\n", path);
+
+      _dbus_string_free (&address);
+      _dbus_string_free (&prefix);
+
+      _DBUS_ASSERT_ERROR_IS_CLEAR (error);
+      return DBUS_TRANSPORT_OPEN_OK;
+        
+        
+      l_failed_1:
+      _dbus_string_free (&prefix);
+
+      l_failed_0:
+      _dbus_string_free (&address);
+    
+      return DBUS_TRANSPORT_OPEN_BAD_ADDRESS;
+    }
+  else
+    {
+      _DBUS_ASSERT_ERROR_IS_CLEAR (error);
+      return DBUS_TRANSPORT_OPEN_NOT_HANDLED;
+    }
+}
+
 /** @} */
 
--- save/dbus-transport-protected.h	2008-08-07 14:44:36.000000000 -0400
+++ dbus/dbus-transport-protected.h	2009-01-17 21:52:23.000000000 -0500
@@ -138,6 +138,10 @@
                                                                 DBusTransport    **transport_p,
                                                                 DBusError         *error);
 
+DBusTransportOpenResult _dbus_transport_open_launchd (DBusAddressEntry  *entry,
+                                                      DBusTransport    **transport_p,
+                                                      DBusError         *error);
+
 DBUS_END_DECLS
 
 #endif /* DBUS_TRANSPORT_PROTECTED_H */
--- save/dbus-transport.c	2009-01-17 16:59:38.000000000 -0500
+++ dbus/dbus-transport.c	2009-01-17 18:47:45.000000000 -0500
@@ -333,6 +333,9 @@
   { _dbus_transport_open_socket },
   { _dbus_transport_open_platform_specific },
   { _dbus_transport_open_autolaunch }
+#ifdef DBUS_ENABLE_LAUNCHD
+  , {_dbus_transport_open_launchd }
+#endif
 #ifdef DBUS_BUILD_TESTS
   , { _dbus_transport_open_debug_pipe }
 #endif

