Ticket #27555: 0004-enable-launchd.patch
File 0004-enable-launchd.patch, 14.3 KB (added by monty19@…, 14 years ago) |
---|
-
README.launchd
diff -urN dbus-1.4.0-old/README.launchd dbus-1.4.0-new/README.launchd
old new 1 Launchd[1,2] replaces init, inetd and cron on Mac OS X since 10.4 "Tiger". 2 dbus uses this service to provide a common session bus address for each user 3 and so deprecates the X11 enabled dbus-launcher. 4 5 [1] http://developer.apple.com/MacOsX/launchd.html 6 [2] http://launchd.macosforge.org/ 7 8 9 Setup 10 === 11 12 Configure with --enable-launchd and --without-x (X11 should not harm but it's 13 simply not necessary any more) 14 After installation, to prevent a reboot, load the dbus session starter into 15 launchd by executing: 16 $ launchctl load /Library/LaunchAgents/org.freedesktop.dbus-session.plist 17 18 You can change the launch agent dir via configure, but it's not recommended. 19 Make sure to execute the above line as the actual user for which you want to 20 use a session bus since launchd manages its agents on a per user basis. 21 22 23 How it works 24 === 25 26 Launchd allocates a socket and provides the unix path to it via the variable 27 DBUS_LAUNCHD_SESSION_BUS_SOCKET in launchd's environment. Every process 28 spawned by launchd (or dbus-daemon, if stared by launchd) can access it through 29 its own environment. Other processes can query launchd for it by executing: 30 $ launchctl getenv DBUS_LAUNCHD_SESSION_BUS_SOCKET 31 However, this is normally done by the dbus client lib for you. 32 33 If launchd start dbus-daemon with a config file containing a "launchd:env=FOO" 34 address, as the default session config does with env=DBUS_LAUNCHD_SESSION_BUS_SOCKET, 35 the daemon will get the file descriptor from launchd and start listening on it. 36 The environment variable is used to get the actual socket path which is passed 37 to every service spawned by dbus-daemon as a result from autolaunch messages. 38 Please note that it's not possible to start dbus-daemon manually when using a 39 "launchd:" address. Only child processes of launchd can access the above 40 mentioned file descriptor! 41 42 To create custom buses just set up an other launch agent. As a quick start copy 43 /Library/LaunchAgents/org.freedesktop.dbus-session.plist, change the label 44 to i.e. "org.freedesktop.dbus-foo" and change the SecureSocketWithKey value, 45 i.e. to "DBUS_LAUNCHD_FOO_BUS_SOCKET". This environment variable has to be set 46 in the config file for your new bus in the <listen> element (see session.config). 47 Then edit your /Library/LaunchAgents/org.freedesktop.dbus-foo.plist to start 48 dbus-daemon with "--config-file=/opt/local/etc/dbus-1/foo.conf" instead of 49 "--session". Now load the new plist onto launchd as described in the setup 50 section of this document. 51 Executing "launchctl export" should now give you two sockets, one in 52 DBUS_LAUNCHD_SESSION_BUS_SOCKET and the new DBUS_LAUNCHD_FOO_BUS_SOCKET. 53 To connect to this new bus use "launchd:env=DBUS_LAUNCHD_FOO_BUS_SOCKET". 54 55 Since Mac OS X 10.5 "Leopard" you can also configure launchd to start 56 dbus-daemon on demand as soon as some process connects to the socket. Since 57 it's broken on 10.4 this feature is disabled per default. Look at 58 /Library/LaunchAgents/org.freedesktop.dbus-session.plist to change it. 59 60 On the client side, the envvar DBUS_SESSION_BUS_ADDRESS can be normally used 61 but if it's not set, launchd is queried for the session bus socket. -
bus/Makefile.am
diff -urN dbus-1.4.0-old/bus/Makefile.am dbus-1.4.0-new/bus/Makefile.am
old new 9 9 10 10 CONFIG_IN_FILES= \ 11 11 session.conf.in \ 12 system.conf.in 12 system.conf.in \ 13 org.freedesktop.dbus-session.plist.in 13 14 14 15 config_DATA= \ 15 16 session.conf \ 16 17 system.conf 17 18 19 if DBUS_ENABLE_LAUNCHD 20 agentdir=$(LAUNCHD_AGENT_DIR) 21 agent_DATA=org.freedesktop.dbus-session.plist 22 endif 23 18 24 if DBUS_USE_LIBXML 19 25 XML_SOURCES=config-loader-libxml.c 20 26 endif -
bus/org.freedesktop.dbus-session.plist.in
diff -urN dbus-1.4.0-old/bus/org.freedesktop.dbus-session.plist.in dbus-1.4.0-new/bus/org.freedesktop.dbus-session.plist.in
old new 1 <?xml version="1.0" encoding="UTF-8"?> 2 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 3 <plist version="1.0"> 4 <dict> 5 <key>Label</key> 6 <string>org.freedesktop.dbus-session</string> 7 8 <key>ServiceIPC</key> 9 <true/> 10 11 <!-- bug in 10.4's launchd - on-demand loading does not work --> 12 <key>OnDemand</key> 13 <false /> 14 15 <key>ProgramArguments</key> 16 <array> 17 <string>@DBUS_DAEMONDIR@/dbus-daemon</string> 18 <string>--nofork</string> 19 <string>--session</string> 20 </array> 21 22 <key>Sockets</key> 23 <dict> 24 <key>unix_domain_listener</key> 25 <dict> 26 <key>SecureSocketWithKey</key> 27 <string>DBUS_LAUNCHD_SESSION_BUS_SOCKET</string> 28 </dict> 29 </dict> 30 </dict> 31 </plist> 32 -
configure.in
diff -urN dbus-1.4.0-old/configure.in dbus-1.4.0-new/configure.in
old new 135 135 AC_ARG_ENABLE(kqueue, AS_HELP_STRING([--enable-kqueue],[build with kqueue support]),enable_kqueue=$enableval,enable_kqueue=auto) 136 136 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) 137 137 AC_ARG_ENABLE(userdb-cache, AS_HELP_STRING([--enable-userdb-cache],[build with userdb-cache support]),enable_userdb_cache=$enableval,enable_userdb_cache=yes) 138 AC_ARG_ENABLE(launchd, AS_HELP_STRING([--enable-launchd],[build with launchd auto-launch support]),enable_launchd=$enableval,enable_launchd=auto) 138 139 139 140 AC_ARG_WITH(xml, AS_HELP_STRING([--with-xml=[libxml/expat]],[XML library to use])) 140 141 AC_ARG_WITH(init-scripts, AS_HELP_STRING([--with-init-scripts=[redhat]],[Style of init scripts to install])) … … 144 145 AC_ARG_WITH(system-socket, AS_HELP_STRING([--with-system-socket=[filename]],[UNIX domain socket for systemwide daemon])) 145 146 AC_ARG_WITH(console-auth-dir, AS_HELP_STRING([--with-console-auth-dir=[dirname]],[directory to check for console ownerhip])) 146 147 AC_ARG_WITH(console-owner-file, AS_HELP_STRING([--with-console-owner-file=[filename]],[file whose owner determines current console owner])) 148 AC_ARG_WITH(launchd-agent-dir, AS_HELP_STRING([--with-launchd-agent-dir=[dirname]],[directory to put the launchd agent (default: /Library/LaunchAgents)])) 147 149 AC_ARG_WITH(dbus_user, AS_HELP_STRING([--with-dbus-user=<user>],[User for running the DBUS daemon (messagebus)])) 148 150 AC_ARG_WITH(dbus_daemondir, AS_HELP_STRING([--with-dbus-daemondir=[dirname]],[Directory for installing the DBUS daemon])) 149 151 … … 922 924 923 925 AM_CONDITIONAL(DBUS_BUS_ENABLE_KQUEUE, test x$have_kqueue = xyes) 924 926 927 # launchd checks 928 if test x$enable_launchd = xno ; then 929 have_launchd=no 930 else 931 have_launchd=yes 932 AC_CHECK_HEADER([launch.h], , have_launchd=no) 933 AC_PATH_PROG([LAUNCHCTL], [launchctl]) 934 if test "x$LAUNCHCTL" = "x"; then 935 have_launchd=no 936 fi 937 938 if test x$enable_launchd = xyes && test x$have_launchd = xno ; then 939 AC_MSG_ERROR([launchd support explicitly enabled but not available]) 940 fi 941 fi 942 943 dnl check if launchd is enabled 944 if test x$have_launchd = xyes; then 945 AC_DEFINE(DBUS_ENABLE_LAUNCHD,1,[Use launchd autolaunch]) 946 fi 947 948 AM_CONDITIONAL(DBUS_ENABLE_LAUNCHD, test x$have_launchd = xyes) 949 950 #### Directory to place launchd agent file 951 if test "x$with_launchd_agent_dir" = "x"; then 952 LAUNCHD_AGENT_DIR="/Library/LaunchAgents" 953 else 954 LAUNCHD_AGENT_DIR="$with_launchd_agent_dir" 955 fi 956 957 AC_SUBST(LAUNCHD_AGENT_DIR) 958 925 959 dnl console owner file 926 960 if test x$enable_console_owner_file = xno ; then 927 961 have_console_owner_file=no; … … 1410 1444 AC_DEFINE_UNQUOTED(DBUS_SYSTEM_BUS_DEFAULT_ADDRESS, "$DBUS_SYSTEM_BUS_DEFAULT_ADDRESS",[The default D-Bus address of the system bus]) 1411 1445 1412 1446 # set up the session bus address 1413 DBUS_SESSION_BUS_DEFAULT_ADDRESS="unix:tmpdir=$DBUS_SESSION_SOCKET_DIR" 1447 if test x$have_launchd = xyes; then 1448 DBUS_SESSION_BUS_DEFAULT_ADDRESS="launchd:env=DBUS_LAUNCHD_SESSION_BUS_SOCKET" 1449 else 1450 DBUS_SESSION_BUS_DEFAULT_ADDRESS="unix:tmpdir=$DBUS_SESSION_SOCKET_DIR" 1451 fi 1414 1452 AC_SUBST(DBUS_SESSION_BUS_DEFAULT_ADDRESS) 1415 1453 1416 1454 #### Set up the pid file … … 1551 1589 DBUS_SESSION_SOCKET_DIR=$DEFAULT_SOCKET_DIR 1552 1590 fi 1553 1591 AC_DEFINE_UNQUOTED(DBUS_SESSION_SOCKET_DIR, "$DBUS_SESSION_SOCKET_DIR", [Where per-session bus puts its sockets]) 1554 AC_SUBST(DBUS_SESSION_SOCKET_DIR)1555 1592 1556 1593 if test x$dbus_win = xyes; then 1557 1594 DBUS_SESSION_BUS_DEFAULT_ADDRESS="nonce-tcp:" … … 1579 1616 bus/system.conf 1580 1617 bus/session.conf 1581 1618 bus/messagebus 1619 bus/org.freedesktop.dbus-session.plist 1582 1620 bus/messagebus-config 1583 1621 bus/rc.messagebus 1584 1622 bus/dbus-daemon.1 … … 1650 1688 Building Doxygen docs: ${enable_doxygen_docs} 1651 1689 Building XML docs: ${enable_xml_docs} 1652 1690 Building cache support: ${enable_userdb_cache} 1691 Building launchd support: ${have_launchd} 1653 1692 Gettext libs (empty OK): ${INTLLIBS} 1654 1693 Using XML parser: ${with_xml} 1655 1694 Init scripts style: ${with_init_scripts} … … 1663 1702 Console owner file path: ${DBUS_CONSOLE_OWNER_FILE} 1664 1703 System bus user: ${DBUS_USER} 1665 1704 Session bus services dir: ${EXPANDED_DATADIR}/dbus-1/services 1666 'make check' socket dir: ${TEST_SOCKET_DIR} 1667 " 1705 'make check' socket dir: ${TEST_SOCKET_DIR}" 1706 1707 if test x$have_launchd = xyes; then 1708 echo " launchd agent dir: ${LAUNCHD_AGENT_DIR}" 1709 fi 1710 echo 1668 1711 1669 1712 if test x$enable_tests = xyes; then 1670 1713 echo "NOTE: building with unit tests increases the size of the installed library and renders it insecure." -
dbus/Makefile.am
diff -urN dbus-1.4.0-old/dbus/Makefile.am dbus-1.4.0-new/dbus/Makefile.am
old new 159 159 dbus-server.c \ 160 160 dbus-server-debug-pipe.c \ 161 161 dbus-server-debug-pipe.h \ 162 dbus-server-launchd.c \ 163 dbus-server-launchd.h \ 162 164 dbus-server-protected.h \ 163 165 dbus-server-socket.c \ 164 166 dbus-server-socket.h \ -
dbus/dbus-server-unix.c
diff -urN dbus-1.4.0-old/dbus/dbus-server-unix.c dbus-1.4.0-new/dbus/dbus-server-unix.c
old new 25 25 #include "dbus-internals.h" 26 26 #include "dbus-server-unix.h" 27 27 #include "dbus-server-socket.h" 28 #include "dbus-server-launchd.h" 28 29 #include "dbus-transport-unix.h" 29 30 #include "dbus-connection-internal.h" 30 31 #include "dbus-sysdeps-unix.h" … … 179 180 180 181 return DBUS_SERVER_LISTEN_OK; 181 182 } 183 184 else if (strcmp (method, "launchd") == 0) 185 { 186 const char *launchd_env_var = dbus_address_entry_get_value (entry, "env"); 187 if (launchd_env_var == NULL) 188 { 189 _dbus_set_bad_address (error, "launchd", "env", NULL); 190 return DBUS_SERVER_LISTEN_DID_NOT_CONNECT; 191 } 192 *server_p = _dbus_server_new_for_launchd (launchd_env_var, error); 193 194 if (*server_p != NULL) 195 { 196 _DBUS_ASSERT_ERROR_IS_CLEAR(error); 197 return DBUS_SERVER_LISTEN_OK; 198 } 199 else 200 { 201 _DBUS_ASSERT_ERROR_IS_SET(error); 202 return DBUS_SERVER_LISTEN_DID_NOT_CONNECT; 203 } 204 } 205 182 206 else 183 207 { 184 208 /* If we don't handle the method, we return NULL with the -
dbus/dbus-sysdeps.h
diff -urN dbus-1.4.0-old/dbus/dbus-sysdeps.h dbus-1.4.0-new/dbus/dbus-sysdeps.h
old new 187 187 dbus_bool_t _dbus_send_credentials_socket (int server_fd, 188 188 DBusError *error); 189 189 190 dbus_bool_t _dbus_lookup_launchd_socket (DBusString *socket_path, 191 const char *launchd_env_var, 192 DBusError *error); 193 190 194 dbus_bool_t _dbus_credentials_add_from_user (DBusCredentials *credentials, 191 195 const DBusString *username); 192 196 dbus_bool_t _dbus_credentials_add_from_current_process (DBusCredentials *credentials); -
dbus/dbus-transport-unix.c
diff -urN dbus-1.4.0-old/dbus/dbus-transport-unix.c dbus-1.4.0-new/dbus/dbus-transport-unix.c
old new 170 170 return DBUS_TRANSPORT_OPEN_OK; 171 171 } 172 172 } 173 else if (strcmp (method, "launchd") == 0) 174 { 175 DBusError tmp_error = DBUS_ERROR_INIT; 176 const char *launchd_env_var = dbus_address_entry_get_value (entry, "env"); 177 const char *launchd_socket; 178 DBusString socket_path; 179 dbus_bool_t valid_socket; 180 181 if (!_dbus_string_init (&socket_path)) 182 { 183 _DBUS_SET_OOM (error); 184 return FALSE; 185 } 186 187 if (launchd_env_var == NULL) 188 { 189 _dbus_set_bad_address (error, "launchd", "env", NULL); 190 return DBUS_TRANSPORT_OPEN_BAD_ADDRESS; 191 } 192 193 valid_socket = _dbus_lookup_launchd_socket (&socket_path, launchd_env_var, error); 194 195 if (dbus_error_is_set(error)) 196 { 197 _dbus_string_free(&socket_path); 198 return DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT; 199 } 200 201 if (!valid_socket) 202 { 203 dbus_set_error(&tmp_error, DBUS_ERROR_BAD_ADDRESS, 204 "launchd's env var %s does not exist", launchd_env_var); 205 dbus_error_free(error); 206 dbus_move_error(&tmp_error, error); 207 return DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT; 208 } 209 210 launchd_socket = _dbus_string_get_const_data(&socket_path); 211 *transport_p = _dbus_transport_new_for_domain_socket (launchd_socket, FALSE, error); 212 213 if (*transport_p == NULL) 214 { 215 _DBUS_ASSERT_ERROR_IS_SET (error); 216 return DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT; 217 } 218 else 219 { 220 _DBUS_ASSERT_ERROR_IS_CLEAR (error); 221 return DBUS_TRANSPORT_OPEN_OK; 222 } 223 } 173 224 else 174 225 { 175 226 _DBUS_ASSERT_ERROR_IS_CLEAR (error);