29 #include "dbus-server-launchd.h"
39 #ifdef DBUS_ENABLE_LAUNCHD
44 #include "dbus-misc.h"
45 #include "dbus-server-socket.h"
46 #include "dbus-sysdeps-unix.h"
69 #ifdef DBUS_ENABLE_LAUNCHD
73 launch_data_t sockets_dict, checkin_response;
74 launch_data_t checkin_request;
75 launch_data_t listening_fd_array, listening_fd;
76 launch_data_t environment_dict, environment_param;
77 const char *launchd_socket_path, *display;
82 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
84 if (launchd_socket_path ==
NULL || *launchd_socket_path ==
'\0')
87 "launchd's environment variable %s is empty, but should contain a socket path.\n", launchd_env_var);
107 if ((checkin_request = launch_data_new_string (LAUNCH_KEY_CHECKIN)) ==
NULL)
110 "launch_data_new_string(\"%s\") Unable to create string.\n",
115 if ((checkin_response = launch_msg (checkin_request)) ==
NULL)
118 "launch_msg(\"%s\") IPC failure: %s\n",
119 LAUNCH_KEY_CHECKIN, strerror (errno));
123 if (LAUNCH_DATA_ERRNO == launch_data_get_type (checkin_response))
126 strerror (launch_data_get_errno (checkin_response)));
131 launch_data_dict_lookup (checkin_response, LAUNCH_JOBKEY_SOCKETS);
132 if (
NULL == sockets_dict)
135 "No sockets found to answer requests on!\n");
140 launch_data_dict_lookup (sockets_dict,
"unix_domain_listener");
141 if (
NULL == listening_fd_array)
144 "No known sockets found to answer requests on!\n");
148 if (launch_data_array_get_count (listening_fd_array) != 1)
151 "Expected 1 socket from launchd, got %d.\n",
152 launch_data_array_get_count (listening_fd_array));
156 listening_fd = launch_data_array_get_index (listening_fd_array, 0);
157 launchd_fd = launch_data_get_fd (listening_fd);
163 _DBUS_ASSERT_ERROR_IS_SET (error);
165 if (display ==
NULL || *display ==
'\0')
167 environment_dict = launch_data_dict_lookup (checkin_response, LAUNCH_JOBKEY_USERENVIRONMENTVARIABLES);
168 if (
NULL == environment_dict)
170 _dbus_warn (
"Unable to retrieve user environment from launchd.");
174 environment_param = launch_data_dict_lookup (environment_dict,
"DISPLAY");
175 if (
NULL == environment_param)
177 _dbus_warn (
"Unable to retrieve DISPLAY from launchd.");
181 display = launch_data_get_string(environment_param);
208 "address type 'launchd' requested, but launchd support not compiled in");