| Launchd[1,2] replaces init, inetd and cron on Mac OS X since 10.4 "Tiger". |
| dbus uses this service to provide a common session bus address for each user |
| and so deprecates the X11 enabled dbus-launcher. |
| |
| [1] http://developer.apple.com/MacOsX/launchd.html |
| [2] http://launchd.macosforge.org/ |
| |
| |
| Setup |
| === |
| |
| Configure with --enable-launchd and --without-x (X11 should not harm but it's |
| simply not necessary any more) |
| After installation, to prevent a reboot, load the dbus session starter into |
| launchd by executing: |
| $ launchctl load /Library/LaunchAgents/org.freedesktop.dbus-session.plist |
| |
| You can change the launch agent dir via configure, but it's not recommended. |
| Make sure to execute the above line as the actual user for which you want to |
| use a session bus since launchd manages its agents on a per user basis. |
| |
| |
| How it works |
| === |
| |
| Launchd allocates a socket and provides the unix path to it via the variable |
| DBUS_LAUNCHD_SESSION_BUS_SOCKET in launchd's environment. Every process |
| spawned by launchd (or dbus-daemon, if stared by launchd) can access it through |
| its own environment. Other processes can query launchd for it by executing: |
| $ launchctl getenv DBUS_LAUNCHD_SESSION_BUS_SOCKET |
| However, this is normally done by the dbus client lib for you. |
| |
| If launchd start dbus-daemon with a config file containing a "launchd:env=FOO" |
| address, as the default session config does with env=DBUS_LAUNCHD_SESSION_BUS_SOCKET, |
| the daemon will get the file descriptor from launchd and start listening on it. |
| The environment variable is used to get the actual socket path which is passed |
| to every service spawned by dbus-daemon as a result from autolaunch messages. |
| Please note that it's not possible to start dbus-daemon manually when using a |
| "launchd:" address. Only child processes of launchd can access the above |
| mentioned file descriptor! |
| |
| To create custom buses just set up an other launch agent. As a quick start copy |
| /Library/LaunchAgents/org.freedesktop.dbus-session.plist, change the label |
| to i.e. "org.freedesktop.dbus-foo" and change the SecureSocketWithKey value, |
| i.e. to "DBUS_LAUNCHD_FOO_BUS_SOCKET". This environment variable has to be set |
| in the config file for your new bus in the <listen> element (see session.config). |
| Then edit your /Library/LaunchAgents/org.freedesktop.dbus-foo.plist to start |
| dbus-daemon with "--config-file=/opt/local/etc/dbus-1/foo.conf" instead of |
| "--session". Now load the new plist onto launchd as described in the setup |
| section of this document. |
| Executing "launchctl export" should now give you two sockets, one in |
| DBUS_LAUNCHD_SESSION_BUS_SOCKET and the new DBUS_LAUNCHD_FOO_BUS_SOCKET. |
| To connect to this new bus use "launchd:env=DBUS_LAUNCHD_FOO_BUS_SOCKET". |
| |
| Since Mac OS X 10.5 "Leopard" you can also configure launchd to start |
| dbus-daemon on demand as soon as some process connects to the socket. Since |
| it's broken on 10.4 this feature is disabled per default. Look at |
| /Library/LaunchAgents/org.freedesktop.dbus-session.plist to change it. |
| |
| On the client side, the envvar DBUS_SESSION_BUS_ADDRESS can be normally used |
| but if it's not set, launchd is queried for the session bus socket. |