Ticket #27760: dbus_1.4.10.patch
File dbus_1.4.10.patch, 36.8 KB (added by mtalexander (Mike Alexander), 13 years ago) |
---|
-
files/0005-dont-dup-closed-stdin.patch
2 2 =================================================================== 3 3 --- dbus-1.2.16.orig/dbus/dbus-sysdeps-unix.c 2009-10-14 14:43:57.000000000 +0200 4 4 +++ dbus-1.2.16/dbus/dbus-sysdeps-unix.c 2009-10-14 14:44:39.000000000 +0200 5 @@ - 2968,7 +2968,7 @@5 @@ -3128,7 +3128,7 @@ 6 6 close (1); /* close stdout */ 7 7 close (2); /* close stderr */ 8 8 -
files/0003-look-up-DISPLAY-from-launchd-if-not-initialized.patch
1 From e487f8a50bddd4de20a79532b0f940b8a0177e43 Mon Sep 17 00:00:00 20012 From: Benjamin Reed <rangerrick@befunk.com>3 Date: Tue, 21 Jul 2009 10:33:32 -04004 Subject: [PATCH 3/7] look up DISPLAY from launchd if not initialized5 6 ---7 dbus/dbus-server-launchd.c | 25 ++++++++++++++++++++++++-8 1 files changed, 24 insertions(+), 1 deletions(-)9 10 diff --git a/dbus/dbus-server-launchd.c b/dbus/dbus-server-launchd.c11 index bcfb558..52782aa 10064412 --- a/dbus/dbus-server-launchd.c13 +++ b/dbus/dbus-server-launchd.c14 @@ -71,9 +71,10 @@ _dbus_server_new_for_launchd (const char *launchd_env_var, DBusError * error)15 launch_data_t checkin_request;16 launch_data_t listening_fd_array, listening_fd;17 launch_data_t environment_dict, environment_param;18 - const char *launchd_socket_path;19 + const char *launchd_socket_path, *display;20 21 launchd_socket_path = _dbus_getenv (launchd_env_var);22 + display = _dbus_getenv ("DISPLAY");23 24 _DBUS_ASSERT_ERROR_IS_CLEAR (error);25 26 @@ -158,6 +159,28 @@ _dbus_server_new_for_launchd (const char *launchd_env_var, DBusError * error)27 {28 _DBUS_ASSERT_ERROR_IS_SET (error);29 goto l_failed_0;30 + if (display == NULL || *display == '\0')31 + {32 + environment_dict = launch_data_dict_lookup (checkin_response, LAUNCH_JOBKEY_USERENVIRONMENTVARIABLES);33 + if (NULL == environment_dict)34 + {35 + _dbus_warn ("Unable to retrieve user environment from launchd.");36 + }37 + else38 + {39 + environment_param = launch_data_dict_lookup (environment_dict, "DISPLAY");40 + if (NULL == environment_param)41 + {42 + _dbus_warn ("Unable to retrieve DISPLAY from launchd.");43 + }44 + else45 + {46 + display = launch_data_get_string(environment_param);47 + _dbus_setenv ("DISPLAY", display);48 + }49 + }50 + }51 +52 }53 54 server = _dbus_server_new_for_socket (&launchd_fd, 1, &address);55 --56 1.6.3.257 -
files/0004-enable-launchd.patch
1 From bb7496118f9f640209b4c49c8f5691c497aad381 Mon Sep 17 00:00:00 20012 From: Benjamin Reed <rangerrick@befunk.com>3 Date: Sun, 19 Jul 2009 11:45:34 -04004 Subject: [PATCH 4/7] enable launchd5 6 This patch enables support for Mac OS X's launch daemon7 for startup as well as sharing of the DBus session bus8 environment. It includes a LaunchAgent plist for automatic9 start of the session bus.10 ---11 README.launchd | 61 +++++++++++++++++++++++++++++12 bus/Makefile.am | 8 +++-13 bus/org.freedesktop.dbus-session.plist.in | 31 +++++++++++++++14 configure.in | 50 ++++++++++++++++++++++--15 dbus/Makefile.am | 2 +16 dbus/dbus-server-unix.c | 23 +++++++++++17 dbus/dbus-sysdeps-unix.h | 4 ++18 dbus/dbus-transport-unix.c | 51 ++++++++++++++++++++++++19 8 files changed, 225 insertions(+), 5 deletions(-)20 create mode 100644 README.launchd21 create mode 100644 bus/org.freedesktop.dbus-session.plist.in22 23 diff --git a/README.launchd b/README.launchd24 new file mode 10064425 index 0000000..701e57d26 --- /dev/null27 +++ b/README.launchd28 @@ -0,0 +1,61 @@29 +Launchd[1,2] replaces init, inetd and cron on Mac OS X since 10.4 "Tiger".30 +dbus uses this service to provide a common session bus address for each user31 +and so deprecates the X11 enabled dbus-launcher.32 +33 +[1] http://developer.apple.com/MacOsX/launchd.html34 +[2] http://launchd.macosforge.org/35 +36 +37 +Setup38 +===39 +40 +Configure with --enable-launchd and --without-x (X11 should not harm but it's41 +simply not necessary any more)42 +After installation, to prevent a reboot, load the dbus session starter into43 +launchd by executing:44 +$ launchctl load /Library/LaunchAgents/org.freedesktop.dbus-session.plist45 +46 +You can change the launch agent dir via configure, but it's not recommended.47 +Make sure to execute the above line as the actual user for which you want to48 +use a session bus since launchd manages its agents on a per user basis.49 +50 +51 +How it works52 +===53 +54 +Launchd allocates a socket and provides the unix path to it via the variable55 +DBUS_LAUNCHD_SESSION_BUS_SOCKET in launchd's environment. Every process56 +spawned by launchd (or dbus-daemon, if stared by launchd) can access it through57 +its own environment. Other processes can query launchd for it by executing:58 +$ launchctl getenv DBUS_LAUNCHD_SESSION_BUS_SOCKET59 +However, this is normally done by the dbus client lib for you.60 +61 +If launchd start dbus-daemon with a config file containing a "launchd:env=FOO"62 +address, as the default session config does with env=DBUS_LAUNCHD_SESSION_BUS_SOCKET,63 +the daemon will get the file descriptor from launchd and start listening on it.64 +The environment variable is used to get the actual socket path which is passed65 +to every service spawned by dbus-daemon as a result from autolaunch messages.66 +Please note that it's not possible to start dbus-daemon manually when using a67 +"launchd:" address. Only child processes of launchd can access the above68 +mentioned file descriptor!69 +70 +To create custom buses just set up an other launch agent. As a quick start copy71 +/Library/LaunchAgents/org.freedesktop.dbus-session.plist, change the label72 +to i.e. "org.freedesktop.dbus-foo" and change the SecureSocketWithKey value,73 +i.e. to "DBUS_LAUNCHD_FOO_BUS_SOCKET". This environment variable has to be set74 +in the config file for your new bus in the <listen> element (see session.config).75 +Then edit your /Library/LaunchAgents/org.freedesktop.dbus-foo.plist to start76 +dbus-daemon with "--config-file=/opt/local/etc/dbus-1/foo.conf" instead of77 +"--session". Now load the new plist onto launchd as described in the setup78 +section of this document.79 +Executing "launchctl export" should now give you two sockets, one in80 +DBUS_LAUNCHD_SESSION_BUS_SOCKET and the new DBUS_LAUNCHD_FOO_BUS_SOCKET.81 +To connect to this new bus use "launchd:env=DBUS_LAUNCHD_FOO_BUS_SOCKET".82 +83 +Since Mac OS X 10.5 "Leopard" you can also configure launchd to start84 +dbus-daemon on demand as soon as some process connects to the socket. Since85 +it's broken on 10.4 this feature is disabled per default. Look at86 +/Library/LaunchAgents/org.freedesktop.dbus-session.plist to change it.87 +88 +On the client side, the envvar DBUS_SESSION_BUS_ADDRESS can be normally used89 +but if it's not set, launchd is queried for the session bus socket.90 diff --git a/bus/Makefile.am b/bus/Makefile.am91 index 3b4f69d..420742b 10064492 --- a/bus/Makefile.am93 +++ b/bus/Makefile.am94 @@ -9,12 +9,18 @@ EFENCE=95 96 CONFIG_IN_FILES= \97 session.conf.in \98 - system.conf.in99 + system.conf.in \100 + org.freedesktop.dbus-session.plist.in101 102 config_DATA= \103 session.conf \104 system.conf105 106 +if DBUS_ENABLE_LAUNCHD107 +agentdir=$(LAUNCHD_AGENT_DIR)108 +agent_DATA=org.freedesktop.dbus-session.plist109 +endif110 +111 if DBUS_USE_LIBXML112 XML_SOURCES=config-loader-libxml.c113 endif114 diff --git a/bus/org.freedesktop.dbus-session.plist.in b/bus/org.freedesktop.dbus-session.plist.in115 new file mode 100644116 index 0000000..ac5a9d4117 --- /dev/null118 +++ b/bus/org.freedesktop.dbus-session.plist.in119 @@ -0,0 +1,31 @@120 +<?xml version="1.0" encoding="UTF-8"?>121 +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">122 +<plist version="1.0">123 +<dict>124 + <key>Label</key>125 + <string>org.freedesktop.dbus-session</string>126 +127 + <key>ServiceIPC</key>128 + <true/>129 +130 + <!-- bug in 10.4's launchd - on-demand loading does not work -->131 + <key>OnDemand</key>132 + <false />133 +134 + <key>ProgramArguments</key>135 + <array>136 + <string>@DBUS_DAEMONDIR@/dbus-daemon</string>137 + <string>--nofork</string>138 + <string>--session</string>139 + </array>140 +141 + <key>Sockets</key>142 + <dict>143 + <key>unix_domain_listener</key>144 + <dict>145 + <key>SecureSocketWithKey</key>146 + <string>DBUS_LAUNCHD_SESSION_BUS_SOCKET</string>147 + </dict>148 + </dict>149 +</dict>150 +</plist>151 diff --git a/configure.in b/configure.in152 index 5b88385..85c3915 100644153 --- a/configure.in154 +++ b/configure.in155 @@ -79,6 +79,7 @@ AC_ARG_ENABLE(inotify, AS_HELP_STRING([--enable-inotify],[build with inotify sup156 AC_ARG_ENABLE(kqueue, AS_HELP_STRING([--enable-kqueue],[build with kqueue support]),enable_kqueue=$enableval,enable_kqueue=auto)157 AC_ARG_ENABLE(console-owner-file, AS_HELP_STRING([--enable-console-owner-file],[enable console owner file]),enable_console_owner_file=$enableval,enable_console_owner_file=auto)158 AC_ARG_ENABLE(userdb-cache, AS_HELP_STRING([--enable-userdb-cache],[build with userdb-cache support]),enable_userdb_cache=$enableval,enable_userdb_cache=yes)159 +AC_ARG_ENABLE(launchd, AS_HELP_STRING([--enable-launchd],[build with launchd auto-launch support]),enable_launchd=$enableval,enable_launchd=auto)160 161 AC_ARG_WITH(xml, AS_HELP_STRING([--with-xml=[libxml/expat]],[XML library to use]))162 AC_ARG_WITH(init-scripts, AS_HELP_STRING([--with-init-scripts=[redhat]],[Style of init scripts to install]))163 @@ -88,6 +89,7 @@ AC_ARG_WITH(system-pid-file, AS_HELP_STRING([--with-system-pid-file=[pidfile]],[164 AC_ARG_WITH(system-socket, AS_HELP_STRING([--with-system-socket=[filename]],[UNIX domain socket for systemwide daemon]))165 AC_ARG_WITH(console-auth-dir, AS_HELP_STRING([--with-console-auth-dir=[dirname]],[directory to check for console ownerhip]))166 AC_ARG_WITH(console-owner-file, AS_HELP_STRING([--with-console-owner-file=[filename]],[file whose owner determines current console owner]))167 +AC_ARG_WITH(launchd-agent-dir, AS_HELP_STRING([--with-launchd-agent-dir=[dirname]],[directory to put the launchd agent (default: /Library/LaunchAgents)]))168 AC_ARG_WITH(dbus_user, AS_HELP_STRING([--with-dbus-user=<user>],[User for running the DBUS daemon (messagebus)]))169 AC_ARG_WITH(dbus_daemondir, AS_HELP_STRING([--with-dbus-daemondir=[dirname]],[Directory for installing the DBUS daemon]))170 171 @@ -817,6 +819,38 @@ fi172 173 AM_CONDITIONAL(DBUS_BUS_ENABLE_KQUEUE, test x$have_kqueue = xyes)174 175 +# launchd checks176 +if test x$enable_launchd = xno ; then177 + have_launchd=no178 +else179 + have_launchd=yes180 + AC_CHECK_HEADER([launch.h], , have_launchd=no)181 + AC_PATH_PROG([LAUNCHCTL], [launchctl])182 + if test "x$LAUNCHCTL" = "x"; then183 + have_launchd=no184 + fi185 +186 + if test x$enable_launchd = xyes && test x$have_launchd = xno ; then187 + AC_MSG_ERROR([launchd support explicitly enabled but not available])188 + fi189 +fi190 +191 +dnl check if launchd is enabled192 +if test x$have_launchd = xyes; then193 + AC_DEFINE(DBUS_ENABLE_LAUNCHD,1,[Use launchd autolaunch])194 +fi195 +196 +AM_CONDITIONAL(DBUS_ENABLE_LAUNCHD, test x$have_launchd = xyes)197 +198 +#### Directory to place launchd agent file199 +if test "x$with_launchd_agent_dir" = "x"; then200 + LAUNCHD_AGENT_DIR="/Library/LaunchAgents"201 +else202 + LAUNCHD_AGENT_DIR="$with_launchd_agent_dir"203 +fi204 +205 +AC_SUBST(LAUNCHD_AGENT_DIR)206 +207 dnl console owner file208 if test x$enable_console_owner_file = xno ; then209 have_console_owner_file=no;210 @@ -1287,7 +1321,11 @@ AC_SUBST(DBUS_SYSTEM_BUS_DEFAULT_ADDRESS)211 AC_DEFINE_UNQUOTED(DBUS_SYSTEM_BUS_DEFAULT_ADDRESS, "$DBUS_SYSTEM_BUS_DEFAULT_ADDRESS",[The default D-Bus address of the system bus])212 213 # set up the session bus address214 -DBUS_SESSION_BUS_DEFAULT_ADDRESS="unix:tmpdir=$DBUS_SESSION_SOCKET_DIR"215 +if test x$have_launchd = xyes; then216 + DBUS_SESSION_BUS_DEFAULT_ADDRESS="launchd:env=DBUS_LAUNCHD_SESSION_BUS_SOCKET"217 +else218 + DBUS_SESSION_BUS_DEFAULT_ADDRESS="unix:tmpdir=$DBUS_SESSION_SOCKET_DIR"219 +fi220 AC_SUBST(DBUS_SESSION_BUS_DEFAULT_ADDRESS)221 222 #### Set up the pid file223 @@ -1414,7 +1452,6 @@ else224 DBUS_SESSION_SOCKET_DIR=$DEFAULT_SOCKET_DIR225 fi226 AC_DEFINE_UNQUOTED(DBUS_SESSION_SOCKET_DIR, "$DBUS_SESSION_SOCKET_DIR", [Where per-session bus puts its sockets])227 -AC_SUBST(DBUS_SESSION_SOCKET_DIR)228 229 AC_DEFINE_UNQUOTED(DBUS_UNIX, "1", [Defined on UNIX and Linux systems and not on Windows])230 231 @@ -1436,6 +1473,7 @@ dbus/dbus-arch-deps.h232 bus/system.conf233 bus/session.conf234 bus/messagebus235 +bus/org.freedesktop.dbus-session.plist236 bus/rc.messagebus237 bus/dbus-daemon.1238 Makefile239 @@ -1503,6 +1541,7 @@ echo "240 Building Doxygen docs: ${enable_doxygen_docs}241 Building XML docs: ${enable_xml_docs}242 Building cache support: ${enable_userdb_cache}243 + Building launchd support: ${have_launchd}244 Gettext libs (empty OK): ${INTLLIBS}245 Using XML parser: ${with_xml}246 Init scripts style: ${with_init_scripts}247 @@ -1516,8 +1555,11 @@ echo "248 Console owner file path: ${DBUS_CONSOLE_OWNER_FILE}249 System bus user: ${DBUS_USER}250 Session bus services dir: ${EXPANDED_DATADIR}/dbus-1/services251 - 'make check' socket dir: ${TEST_SOCKET_DIR}252 -"253 + 'make check' socket dir: ${TEST_SOCKET_DIR}"254 +if test x$have_launchd = xyes; then255 + echo " launchd agent dir: ${LAUNCHD_AGENT_DIR}"256 +fi257 +echo258 259 if test x$enable_tests = xyes; then260 echo "NOTE: building with unit tests increases the size of the installed library and renders it insecure."261 diff --git a/dbus/Makefile.am b/dbus/Makefile.am262 index e966a43..ed0a4ae 100644263 --- a/dbus/Makefile.am264 +++ b/dbus/Makefile.am265 @@ -70,6 +70,8 @@ DBUS_LIB_SOURCES= \266 dbus-server.c \267 dbus-server-debug-pipe.c \268 dbus-server-debug-pipe.h \269 + dbus-server-launchd.c \270 + dbus-server-launchd.h \271 dbus-server-protected.h \272 dbus-server-socket.c \273 dbus-server-socket.h \274 diff --git a/dbus/dbus-server-unix.c b/dbus/dbus-server-unix.c275 index 07800c8..55ed9ab 100644276 --- a/dbus/dbus-server-unix.c277 +++ b/dbus/dbus-server-unix.c278 @@ -21,9 +21,11 @@279 *280 */281 282 +#include <config.h>283 #include "dbus-internals.h"284 #include "dbus-server-unix.h"285 #include "dbus-server-socket.h"286 +#include "dbus-server-launchd.h"287 #include "dbus-transport-unix.h"288 #include "dbus-connection-internal.h"289 #include "dbus-sysdeps-unix.h"290 @@ -145,6 +147,27 @@ _dbus_server_listen_platform_specific (DBusAddressEntry *entry,291 return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;292 }293 }294 + else if (strcmp (method, "launchd") == 0)295 + {296 + const char *launchd_env_var = dbus_address_entry_get_value (entry, "env");297 + if (launchd_env_var == NULL)298 + {299 + _dbus_set_bad_address (error, "launchd", "env", NULL);300 + return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;301 + }302 + *server_p = _dbus_server_new_for_launchd (launchd_env_var, error);303 +304 + if (*server_p != NULL)305 + {306 + _DBUS_ASSERT_ERROR_IS_CLEAR(error);307 + return DBUS_SERVER_LISTEN_OK;308 + }309 + else310 + {311 + _DBUS_ASSERT_ERROR_IS_SET(error);312 + return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;313 + }314 + }315 else316 {317 /* If we don't handle the method, we return NULL with the318 diff --git a/dbus/dbus-sysdeps-unix.h b/dbus/dbus-sysdeps-unix.h319 index 96b44e2..8eec96b 100644320 --- a/dbus/dbus-sysdeps-unix.h321 +++ b/dbus/dbus-sysdeps-unix.h322 @@ -79,6 +79,10 @@ dbus_bool_t _dbus_read_credentials (int client_fd,323 dbus_bool_t _dbus_send_credentials (int server_fd,324 DBusError *error);325 326 +dbus_bool_t _dbus_lookup_launchd_socket (DBusString *socket_path,327 + const char *launchd_env_var,328 + DBusError *error);329 +330 /** Information about a UNIX user */331 typedef struct DBusUserInfo DBusUserInfo;332 /** Information about a UNIX group */333 diff --git a/dbus/dbus-transport-unix.c b/dbus/dbus-transport-unix.c334 index 2f2a3da..ce77c57 100644335 --- a/dbus/dbus-transport-unix.c336 +++ b/dbus/dbus-transport-unix.c337 @@ -169,6 +169,57 @@ _dbus_transport_open_platform_specific (DBusAddressEntry *entry,338 return DBUS_TRANSPORT_OPEN_OK;339 }340 }341 + else if (strcmp (method, "launchd") == 0)342 + {343 + DBusError tmp_error = DBUS_ERROR_INIT;344 + const char *launchd_env_var = dbus_address_entry_get_value (entry, "env");345 + const char *launchd_socket;346 + DBusString socket_path;347 + dbus_bool_t valid_socket;348 +349 + if (!_dbus_string_init (&socket_path))350 + {351 + _DBUS_SET_OOM (error);352 + return FALSE;353 + }354 +355 + if (launchd_env_var == NULL)356 + {357 + _dbus_set_bad_address (error, "launchd", "env", NULL);358 + return DBUS_TRANSPORT_OPEN_BAD_ADDRESS;359 + }360 +361 + valid_socket = _dbus_lookup_launchd_socket (&socket_path, launchd_env_var, error);362 +363 + if (dbus_error_is_set(error))364 + {365 + _dbus_string_free(&socket_path);366 + return DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT;367 + }368 +369 + if (!valid_socket)370 + {371 + dbus_set_error(&tmp_error, DBUS_ERROR_BAD_ADDRESS,372 + "launchd's env var %s does not exist", launchd_env_var);373 + dbus_error_free(error);374 + dbus_move_error(&tmp_error, error);375 + return DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT;376 + }377 +378 + launchd_socket = _dbus_string_get_const_data(&socket_path);379 + *transport_p = _dbus_transport_new_for_domain_socket (launchd_socket, FALSE, error);380 +381 + if (*transport_p == NULL)382 + {383 + _DBUS_ASSERT_ERROR_IS_SET (error);384 + return DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT;385 + }386 + else387 + {388 + _DBUS_ASSERT_ERROR_IS_CLEAR (error);389 + return DBUS_TRANSPORT_OPEN_OK;390 + }391 + }392 else393 {394 _DBUS_ASSERT_ERROR_IS_CLEAR (error);395 --396 1.6.3.2397 -
files/0001-make-session-bus-listen-tag-configurable.patch
1 From e0809d6c48641ab11e0dc1b3f537e56692208912 Mon Sep 17 00:00:00 20012 From: Benjamin Reed <rangerrick@befunk.com>3 Date: Sun, 19 Jul 2009 11:30:39 -04004 Subject: [PATCH 1/7] make session bus <listen> tag configurable5 6 ---7 bus/session.conf.in | 2 +-8 configure.in | 4 ++++9 2 files changed, 5 insertions(+), 1 deletions(-)10 11 diff --git a/bus/session.conf.in b/bus/session.conf.in12 index 85395c5..e121ff9 10064413 --- a/bus/session.conf.in14 +++ b/bus/session.conf.in15 @@ -12,7 +12,7 @@16 the behavior of child processes. -->17 <keep_umask/>18 19 - <listen>unix:tmpdir=@DBUS_SESSION_SOCKET_DIR@</listen>20 + <listen>@DBUS_SESSION_BUS_DEFAULT_ADDRESS@</listen>21 22 <standard_session_servicedirs />23 24 diff --git a/configure.in b/configure.in25 index d79d655..5b88385 10064426 --- a/configure.in27 +++ b/configure.in28 @@ -1286,6 +1286,10 @@ DBUS_SYSTEM_BUS_DEFAULT_ADDRESS="unix:path=$DBUS_SYSTEM_SOCKET"29 AC_SUBST(DBUS_SYSTEM_BUS_DEFAULT_ADDRESS)30 AC_DEFINE_UNQUOTED(DBUS_SYSTEM_BUS_DEFAULT_ADDRESS, "$DBUS_SYSTEM_BUS_DEFAULT_ADDRESS",[The default D-Bus address of the system bus])31 32 +# set up the session bus address33 +DBUS_SESSION_BUS_DEFAULT_ADDRESS="unix:tmpdir=$DBUS_SESSION_SOCKET_DIR"34 +AC_SUBST(DBUS_SESSION_BUS_DEFAULT_ADDRESS)35 +36 #### Set up the pid file37 if ! test -z "$with_system_pid_file"; then38 DBUS_SYSTEM_PID_FILE=$with_system_pid_file39 --40 1.6.3.241 -
files/0002-add-launchd-implementation.patch
1 From fe2b03d47790a62bd179e2d443eda194a4f8e4d6 Mon Sep 17 00:00:00 20012 From: Benjamin Reed <rangerrick@befunk.com>3 Date: Sun, 19 Jul 2009 11:44:50 -04004 Subject: [PATCH 2/7] add launchd implementation5 6 ---7 dbus/dbus-server-launchd.c | 186 ++++++++++++++++++++++++++++++++++++++++++++8 dbus/dbus-server-launchd.h | 35 ++++++++9 dbus/dbus-sysdeps-unix.c | 101 ++++++++++++++++++++++++10 3 files changed, 322 insertions(+), 0 deletions(-)11 create mode 100644 dbus/dbus-server-launchd.c12 create mode 100644 dbus/dbus-server-launchd.h13 14 Index: dbus-1.2.16/dbus/dbus-server-launchd.c15 ===================================================================16 --- /dev/null 1970-01-01 00:00:00.000000000 +000017 +++ dbus-1.2.16/dbus/dbus-server-launchd.c 2009-10-13 11:43:14.000000000 +020018 @@ -0,0 +1,186 @@19 +/* dbus-server-launchd.c Server methods for interacting with launchd.20 + * Copyright (C) 2007, Tanner Lovelace <lovelace@wayfarer.org>21 + * Copyright (C) 2008, Colin Walters <walters@verbum.org>22 + * Copyright (C) 2008-2009, Benjamin Reed <rangerrick@befunk.com>23 + * Copyright (C) 2009, Jonas Bähr<jonas.baehr@web.de>24 + *25 + * Permission is hereby granted, free of charge, to any person26 + * obtaining a copy of this software and associated documentation27 + * files (the "Software"), to deal in the Software without28 + * restriction, including without limitation the rights to use, copy,29 + * modify, merge, publish, distribute, sublicense, and/or sell copies30 + * of the Software, and to permit persons to whom the Software is31 + * furnished to do so, subject to the following conditions:32 + *33 + * The above copyright notice and this permission notice shall be34 + * included in all copies or substantial portions of the Software.35 + *36 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,37 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF38 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND39 + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT40 + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,41 + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,42 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER43 + * DEALINGS IN THE SOFTWARE.44 + */45 +46 +#include <config.h>47 +#include "dbus-server-launchd.h"48 +49 +/**50 + * @defgroup DBusServerLaunchd DBusServer implementations for Launchd51 + * @ingroup DBusInternals52 + * @brief Implementation details of DBusServer with Launchd support53 + *54 + * @{55 + */56 +57 +#ifdef DBUS_ENABLE_LAUNCHD58 +#include <launch.h>59 +#include <errno.h>60 +61 +#include "dbus-server-socket.h"62 +63 +/* put other private launchd functions here */64 +65 +#endif /* DBUS_ENABLE_LAUNCHD */66 +67 +/**68 + * @brief Creates a new server from launchd.69 + *70 + * launchd has allocaed a socket for us. We now query launchd for the71 + * file descriptor of this socket and create a server on it.72 + * In addition we inherit launchd's environment which holds a variable73 + * containing the path to the socket. This is used to init the server's74 + * address which is passed to autolaunched services.75 + *76 + * @param launchd_env_var the environment variable which holds the unix path to the socket77 + * @param error location to store reason for failure.78 + * @returns the new server, or #NULL on failure.79 + */80 +81 +DBusServer *82 +_dbus_server_new_for_launchd (const char *launchd_env_var, DBusError * error)83 + {84 +#ifdef DBUS_ENABLE_LAUNCHD85 + DBusServer *server;86 + DBusString address;87 + int launchd_fd;88 + launch_data_t sockets_dict, checkin_response;89 + launch_data_t checkin_request;90 + launch_data_t listening_fd_array, listening_fd;91 + launch_data_t environment_dict, environment_param;92 + const char *launchd_socket_path;93 +94 + launchd_socket_path = _dbus_getenv (launchd_env_var);95 +96 + _DBUS_ASSERT_ERROR_IS_CLEAR (error);97 +98 + if (launchd_socket_path == NULL || *launchd_socket_path == '\0')99 + {100 + dbus_set_error (error, DBUS_ERROR_BAD_ADDRESS,101 + "launchd's environment variable %s is empty, but should contain a socket path.\n", launchd_env_var);102 + return NULL;103 + }104 +105 + if (!_dbus_string_init (&address))106 + {107 + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);108 + return NULL;109 + }110 + if (!_dbus_string_append (&address, "unix:path="))111 + {112 + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);113 + goto l_failed_0;114 + }115 + if (!_dbus_string_append (&address, launchd_socket_path))116 + {117 + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);118 + goto l_failed_0;119 + }120 +121 + if ((checkin_request = launch_data_new_string (LAUNCH_KEY_CHECKIN)) == NULL)122 + {123 + dbus_set_error (error, DBUS_ERROR_NO_MEMORY,124 + "launch_data_new_string(\"%s\") Unable to create string.\n",125 + LAUNCH_KEY_CHECKIN);126 + goto l_failed_0;127 + }128 +129 + if ((checkin_response = launch_msg (checkin_request)) == NULL)130 + {131 + dbus_set_error (error, DBUS_ERROR_IO_ERROR,132 + "launch_msg(\"%s\") IPC failure: %s\n",133 + LAUNCH_KEY_CHECKIN, strerror (errno));134 + goto l_failed_0;135 + }136 +137 + if (LAUNCH_DATA_ERRNO == launch_data_get_type (checkin_response))138 + {139 + dbus_set_error (error, DBUS_ERROR_FAILED, "Check-in failed: %s\n",140 + strerror (launch_data_get_errno (checkin_response)));141 + goto l_failed_0;142 + }143 +144 + sockets_dict =145 + launch_data_dict_lookup (checkin_response, LAUNCH_JOBKEY_SOCKETS);146 + if (NULL == sockets_dict)147 + {148 + dbus_set_error (error, DBUS_ERROR_IO_ERROR,149 + "No sockets found to answer requests on!\n");150 + goto l_failed_0;151 + }152 +153 + listening_fd_array =154 + launch_data_dict_lookup (sockets_dict, "unix_domain_listener");155 + if (NULL == listening_fd_array)156 + {157 + dbus_set_error (error, DBUS_ERROR_IO_ERROR,158 + "No known sockets found to answer requests on!\n");159 + goto l_failed_0;160 + }161 +162 + if (launch_data_array_get_count (listening_fd_array) != 1)163 + {164 + dbus_set_error (error, DBUS_ERROR_LIMITS_EXCEEDED,165 + "Expected 1 socket from launchd, got %d.\n",166 + launch_data_array_get_count (listening_fd_array));167 + goto l_failed_0;168 + }169 +170 + listening_fd = launch_data_array_get_index (listening_fd_array, 0);171 + launchd_fd = launch_data_get_fd (listening_fd);172 +173 + _dbus_fd_set_close_on_exec (launchd_fd);174 +175 + if (launchd_fd < 0)176 + {177 + _DBUS_ASSERT_ERROR_IS_SET (error);178 + goto l_failed_0;179 + }180 +181 + server = _dbus_server_new_for_socket (&launchd_fd, 1, &address);182 + if (server == NULL)183 + {184 + dbus_set_error (error, DBUS_ERROR_NO_SERVER,185 + "Unable to listen on launchd fd %d.", launchd_fd);186 + goto l_failed_0;187 + }188 +189 + _dbus_string_free (&address);190 +191 + return server;192 +193 + l_failed_0:194 + _dbus_string_free (&address);195 +196 + return NULL;197 +#else /* DBUS_ENABLE_LAUNCHD */198 + dbus_set_error (error, DBUS_ERROR_BAD_ADDRESS,199 + "address type 'launchd' requested, but launchd support not compiled in");200 + return NULL;201 +#endif202 + }203 +204 +/** @} */205 Index: dbus-1.2.16/dbus/dbus-server-launchd.h206 ===================================================================207 --- /dev/null 1970-01-01 00:00:00.000000000 +0000208 +++ dbus-1.2.16/dbus/dbus-server-launchd.h 2009-10-13 11:43:14.000000000 +0200209 @@ -0,0 +1,35 @@210 +/* dbus-server-launchd.h Server methods for interacting with launchd.211 +* Copyright (C) 2008, Benjamin Reed <rangerrick@befunk.com>212 +*213 +* Permission is hereby granted, free of charge, to any person214 +* obtaining a copy of this software and associated documentation215 +* files (the "Software"), to deal in the Software without216 +* restriction, including without limitation the rights to use, copy,217 +* modify, merge, publish, distribute, sublicense, and/or sell copies218 +* of the Software, and to permit persons to whom the Software is219 +* furnished to do so, subject to the following conditions:220 +*221 +* The above copyright notice and this permission notice shall be222 +* included in all copies or substantial portions of the Software.223 +*224 +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,225 +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF226 +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND227 +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT228 +* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,229 +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,230 +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER231 +* DEALINGS IN THE SOFTWARE.232 +*/233 +234 +#ifndef DBUS_SERVER_LAUNCHD_H235 +#define DBUS_SERVER_LAUNCHD_H236 +237 +#include <dbus/dbus-internals.h>238 +#include <dbus/dbus-server-protected.h>239 +240 +DBUS_BEGIN_DECLS241 + DBusServer * _dbus_server_new_for_launchd (const char *launchd_env_var, DBusError * error);242 +243 +DBUS_END_DECLS244 +#endif /* DBUS_SERVER_LAUNCHD_H */245 Index: dbus-1.2.16/dbus/dbus-sysdeps-unix.c246 ===================================================================247 --- dbus-1.2.16.orig/dbus/dbus-sysdeps-unix.c 2009-10-13 11:43:07.000000000 +0200248 +++ dbus-1.2.16/dbus/dbus-sysdeps-unix.c 2009-10-13 11:44:10.000000000 +0200249 @@ -3168,6 +3168,102 @@250 #define DBUS_UNIX_STANDARD_SYSTEM_SERVICEDIR "/dbus-1/system-services"251 252 /**253 + * quries launchd for a specific env var which holds the socket path.254 + * @param launchd_env_var the env var to look up255 + * @param error a DBusError to store the error in case of failure256 + * @return the value of the env var257 + */258 +dbus_bool_t259 +_dbus_lookup_launchd_socket (DBusString *socket_path,260 + const char *launchd_env_var,261 + DBusError *error)262 +{263 +#ifdef DBUS_ENABLE_LAUNCHD264 + char *argv[4];265 + int i;266 +267 + _DBUS_ASSERT_ERROR_IS_CLEAR (error);268 +269 + i = 0;270 + argv[i] = "launchctl";271 + ++i;272 + argv[i] = "getenv";273 + ++i;274 + argv[i] = (char*)launchd_env_var;275 + ++i;276 + argv[i] = NULL;277 + ++i;278 +279 + _dbus_assert (i == _DBUS_N_ELEMENTS (argv));280 +281 + if (!_read_subprocess_line_argv(argv[0], TRUE, argv, socket_path, error))282 + {283 + return FALSE;284 + }285 +286 + /* no error, but no result either */287 + if (_dbus_string_get_length(socket_path) == 0)288 + {289 + return FALSE;290 + }291 +292 + /* strip the carriage-return */293 + _dbus_string_shorten(socket_path, 1);294 + return TRUE;295 +#else /* DBUS_ENABLE_LAUNCHD */296 + dbus_set_error(error, DBUS_ERROR_NOT_SUPPORTED,297 + "can't lookup socket from launchd; launchd support not compiled in");298 + return FALSE;299 +#endif300 +}301 +302 +static dbus_bool_t303 +_dbus_lookup_session_address_launchd (DBusString *address, DBusError *error)304 +{305 + dbus_bool_t valid_socket;306 + DBusString socket_path;307 +308 + if (!_dbus_string_init (&socket_path))309 + {310 + _DBUS_SET_OOM (error);311 + return FALSE;312 + }313 +314 + valid_socket = _dbus_lookup_launchd_socket (&socket_path, "DBUS_LAUNCHD_SESSION_BUS_SOCKET", error);315 +316 + if (dbus_error_is_set(error))317 + {318 + _dbus_string_free(&socket_path);319 + return FALSE;320 + }321 +322 + if (!valid_socket)323 + {324 + dbus_set_error(error, "no socket path",325 + "launchd did not provide a socket path, "326 + "verify that org.freedesktop.dbus-session.plist is loaded!");327 + _dbus_string_free(&socket_path);328 + return FALSE;329 + }330 + if (!_dbus_string_append (address, "unix:path="))331 + {332 + _DBUS_SET_OOM (error);333 + _dbus_string_free(&socket_path);334 + return FALSE;335 + }336 + if (!_dbus_string_copy (&socket_path, 0, address,337 + _dbus_string_get_length (address)))338 + {339 + _DBUS_SET_OOM (error);340 + _dbus_string_free(&socket_path);341 + return FALSE;342 + }343 +344 + _dbus_string_free(&socket_path);345 + return TRUE;346 +}347 +348 +/**349 * Determines the address of the session bus by querying a350 * platform-specific method.351 *352 @@ -3191,12 +3287,17 @@353 DBusString *address,354 DBusError *error)355 {356 +#ifdef DBUS_ENABLE_LAUNCHD357 + *supported = TRUE;358 + return _dbus_lookup_session_address_launchd (address, error);359 +#else360 /* On non-Mac Unix platforms, if the session address isn't already361 * set in DBUS_SESSION_BUS_ADDRESS environment variable, we punt and362 * fall back to the autolaunch: global default; see363 * init_session_address in dbus/dbus-bus.c. */364 *supported = FALSE;365 return TRUE;366 +#endif367 }368 369 /** -
files/10.5-launchd.diff
1 --- dbus-1.2.24/bus/org.freedesktop.dbus-session.plist.in.orig 2011-03-22 00:27:21.000000000 +11002 +++ dbus-1.2.24/bus/org.freedesktop.dbus-session.plist.in 2011-03-22 00:31:01.000000000 +11003 @@ -5,13 +5,6 @@4 <key>Label</key>5 <string>org.freedesktop.dbus-session</string>6 7 - <key>ServiceIPC</key>8 - <true/>9 -10 - <!-- bug in 10.4's launchd - on-demand loading does not work -->11 - <key>OnDemand</key>12 - <false />13 -14 <key>ProgramArguments</key>15 <array>16 <string>@DBUS_DAEMONDIR@/dbus-daemon</string> -
Portfile
5 5 PortGroup muniversal 1.0 6 6 7 7 name dbus 8 version 1.2.24 9 revision 1 8 version 1.4.10 10 9 maintainers mcalhoun openmaintainer 11 10 categories devel 12 11 platforms darwin … … 18 17 homepage http://www.freedesktop.org/Software/dbus 19 18 master_sites http://dbus.freedesktop.org/releases/dbus 20 19 21 checksums md5 565346cecd9cfecf1463540c6086cc2c\22 sha1 9593717348ea36ba228b46f165bb67c127c12be8\23 rmd160 2f51def784056bc16fbec2ddc3be22c022a94fb520 checksums md5 402a2f8102bedbe236e2891b2b0f31c2 \ 21 sha1 8a35d253d444d1450a206f717445b371e1d936a1 \ 22 rmd160 7eb3fd372eca42331541eb7465b62c18cd4a2546 24 23 25 24 # There is a proposal to use launchd with dbus (see https://bugs.freedesktop.org/show_bug.cgi?id=14259). 26 patchfiles 0001-make-session-bus-listen-tag-configurable.patch \ 27 0002-add-launchd-implementation.patch \ 28 0003-look-up-DISPLAY-from-launchd-if-not-initialized.patch \ 29 0004-enable-launchd.patch \ 30 0005-dont-dup-closed-stdin.patch \ 25 patchfiles 0005-dont-dup-closed-stdin.patch \ 31 26 0006-bus_system-conf-in.patch 32 27 patch.pre_args -p1 33 28 34 if { $macosx_deployment_target != "10.4" } {35 # Allow on-demand loading for Leopard.36 patchfiles-append 10.5-launchd.diff37 }38 39 29 depends_build \ 40 30 port:pkgconfig 41 31 … … 45 35 46 36 depends_lib port:expat 47 37 48 use_autoreconf yes49 50 38 configure.args --disable-doxygen-docs \ 51 39 --disable-xml-docs \ 52 40 --without-x \ 53 41 --enable-launchd \ 54 --with-launchd-agent-dir=${prefix}/Library/LaunchAgents 42 --with-launchd-agent-dir=${prefix}/Library/LaunchAgents \ 43 --with-session-socket-dir=/tmp \ 44 --with-test-socket-dir=/tmp 55 45 46 activate.asroot yes 47 56 48 pre-configure { 57 49 # Value must be set in pre-configure because dbus_user may change in variant. 58 50 configure.args-append --with-dbus-user=${dbus_user} … … 163 155 file attributes ${prefix}/var/run/dbus -group ${dbus_group} -owner ${dbus_user} 164 156 file attributes ${prefix}/libexec/dbus-daemon-launch-helper -group ${dbus_group} 165 157 158 # Change the share directory so other ports can install to it without running as root. 159 if {[geteuid] == 0 && [getuid] != 0 && ${install.user} != 0} { 160 file attributes ${prefix}/share/dbus-1 -owner ${install.user} -group ${install.group} 161 } 162 166 163 if { ![variant_isset no_startupitem] && ![variant_isset no_root] } { 167 164 file attributes /Library/LaunchAgents/org.freedesktop.dbus-session.plist -owner root -group wheel 168 165 file attributes /Library/LaunchDaemons/[file tail ${plistFl}] -owner root -group wheel