[daemon-fix] Fixed sending daemon match rules for kdbus broadcasts
[platform/upstream/dbus.git] / dbus / dbus-server-launchd.c
index 83d384d..9832875 100644 (file)
@@ -40,6 +40,7 @@
 #include <launch.h>
 #include <errno.h>
 
+#include "dbus-misc.h"
 #include "dbus-server-socket.h"
 
 /* put other private launchd functions here */
@@ -71,9 +72,10 @@ _dbus_server_new_for_launchd (const char *launchd_env_var, DBusError * error)
     launch_data_t checkin_request;
     launch_data_t listening_fd_array, listening_fd;
     launch_data_t environment_dict, environment_param;
-    const char *launchd_socket_path;
+    const char *launchd_socket_path, *display;
 
     launchd_socket_path = _dbus_getenv (launchd_env_var);
+    display = _dbus_getenv ("DISPLAY");
 
     _DBUS_ASSERT_ERROR_IS_CLEAR (error);
 
@@ -158,6 +160,28 @@ _dbus_server_new_for_launchd (const char *launchd_env_var, DBusError * error)
       {
         _DBUS_ASSERT_ERROR_IS_SET (error);
         goto l_failed_0;
+  if (display == NULL || *display == '\0')
+    {
+      environment_dict = launch_data_dict_lookup (checkin_response, LAUNCH_JOBKEY_USERENVIRONMENTVARIABLES);
+      if (NULL == environment_dict)
+        {
+          _dbus_warn ("Unable to retrieve user environment from launchd.");
+        }
+      else
+        {
+          environment_param = launch_data_dict_lookup (environment_dict, "DISPLAY");
+          if (NULL == environment_param)
+            {
+              _dbus_warn ("Unable to retrieve DISPLAY from launchd.");
+            }
+          else
+            {
+              display = launch_data_get_string(environment_param);
+              dbus_setenv ("DISPLAY", display);
+            }
+        }
+    }
+
       }
 
     server = _dbus_server_new_for_socket (&launchd_fd, 1, &address, 0);