1Launchd[1,2] replaces init, inetd and cron on Mac OS X since 10.4 "Tiger". 2dbus uses this service to provide a common session bus address for each user 3and 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 9Setup 10=== 11 12Configure with --enable-launchd and --without-x (X11 should not harm but it's 13simply not necessary any more) 14After installation, to prevent a reboot, load the dbus session starter into 15launchd by executing: 16$ launchctl load /Library/LaunchAgents/org.freedesktop.dbus-session.plist 17 18You can change the launch agent dir via configure, but it's not recommended. 19Make sure to execute the above line as the actual user for which you want to 20use a session bus since launchd manages its agents on a per user basis. 21 22 23How it works 24=== 25 26Launchd allocates a socket and provides the unix path to it via the variable 27DBUS_LAUNCHD_SESSION_BUS_SOCKET in launchd's environment. Every process 28spawned by launchd (or dbus-daemon, if stared by launchd) can access it through 29its own environment. Other processes can query launchd for it by executing: 30$ launchctl getenv DBUS_LAUNCHD_SESSION_BUS_SOCKET 31However, this is normally done by the dbus client lib for you. 32 33If launchd start dbus-daemon with a config file containing a "launchd:env=FOO" 34address, as the default session config does with env=DBUS_LAUNCHD_SESSION_BUS_SOCKET, 35the daemon will get the file descriptor from launchd and start listening on it. 36The environment variable is used to get the actual socket path which is passed 37to every service spawned by dbus-daemon as a result from autolaunch messages. 38Please 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 40mentioned file descriptor! 41 42To 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 44to i.e. "org.freedesktop.dbus-foo" and change the SecureSocketWithKey value, 45i.e. to "DBUS_LAUNCHD_FOO_BUS_SOCKET". This environment variable has to be set 46in the config file for your new bus in the <listen> element (see session.config). 47Then edit your /Library/LaunchAgents/org.freedesktop.dbus-foo.plist to start 48dbus-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 50section of this document. 51Executing "launchctl export" should now give you two sockets, one in 52DBUS_LAUNCHD_SESSION_BUS_SOCKET and the new DBUS_LAUNCHD_FOO_BUS_SOCKET. 53To connect to this new bus use "launchd:env=DBUS_LAUNCHD_FOO_BUS_SOCKET". 54 55Since Mac OS X 10.5 "Leopard" you can also configure launchd to start 56dbus-daemon on demand as soon as some process connects to the socket. Since 57it'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 60On the client side, the envvar DBUS_SESSION_BUS_ADDRESS can be normally used 61but if it's not set, launchd is queried for the session bus socket. 62