29 #include "dbus-server-launchd.h"
39 #ifdef DBUS_ENABLE_LAUNCHD
43 #include "dbus-misc.h"
44 #include "dbus-server-socket.h"
67 #ifdef DBUS_ENABLE_LAUNCHD
71 launch_data_t sockets_dict, checkin_response;
72 launch_data_t checkin_request;
73 launch_data_t listening_fd_array, listening_fd;
74 launch_data_t environment_dict, environment_param;
75 const char *launchd_socket_path, *display;
80 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
82 if (launchd_socket_path ==
NULL || *launchd_socket_path ==
'\0')
85 "launchd's environment variable %s is empty, but should contain a socket path.\n", launchd_env_var);
105 if ((checkin_request = launch_data_new_string (LAUNCH_KEY_CHECKIN)) ==
NULL)
108 "launch_data_new_string(\"%s\") Unable to create string.\n",
113 if ((checkin_response = launch_msg (checkin_request)) ==
NULL)
116 "launch_msg(\"%s\") IPC failure: %s\n",
117 LAUNCH_KEY_CHECKIN, strerror (errno));
121 if (LAUNCH_DATA_ERRNO == launch_data_get_type (checkin_response))
124 strerror (launch_data_get_errno (checkin_response)));
129 launch_data_dict_lookup (checkin_response, LAUNCH_JOBKEY_SOCKETS);
130 if (
NULL == sockets_dict)
133 "No sockets found to answer requests on!\n");
138 launch_data_dict_lookup (sockets_dict,
"unix_domain_listener");
139 if (
NULL == listening_fd_array)
142 "No known sockets found to answer requests on!\n");
146 if (launch_data_array_get_count (listening_fd_array) != 1)
149 "Expected 1 socket from launchd, got %d.\n",
150 launch_data_array_get_count (listening_fd_array));
154 listening_fd = launch_data_array_get_index (listening_fd_array, 0);
155 launchd_fd = launch_data_get_fd (listening_fd);
161 _DBUS_ASSERT_ERROR_IS_SET (error);
163 if (display ==
NULL || *display ==
'\0')
165 environment_dict = launch_data_dict_lookup (checkin_response, LAUNCH_JOBKEY_USERENVIRONMENTVARIABLES);
166 if (
NULL == environment_dict)
168 _dbus_warn (
"Unable to retrieve user environment from launchd.");
172 environment_param = launch_data_dict_lookup (environment_dict,
"DISPLAY");
173 if (
NULL == environment_param)
175 _dbus_warn (
"Unable to retrieve DISPLAY from launchd.");
179 display = launch_data_get_string(environment_param);
191 "Unable to listen on launchd fd %d.", launchd_fd);
205 "address type 'launchd' requested, but launchd support not compiled in");