[OS X] : enable standard (non-launchd) dbus-launch and the use of privileged services via the system bus
Submitted by René J.V. Bertin
Assigned to D-Bus Maintainers
Created attachment 126778 patch against the master branch, #1e43857b
After discussing this on the ML ("about using privileged (KAuth) helpers: system dbus daemon on OS X?") I think it is about time to open a ticket with a patch that I feel I can propose as a reference implementation.
This patch combines 2 wishes of mine:
1- being able to launch a session daemon when logged in remotely to OS X/macOS, i.e. when launchd cannot be used. In that case the OS is used as a traditional Unix, typically with X11 providing remote display, and there are no technical reasons why DBus wouldn't support this mode of operation ("shouldn't" may be a different thing). I'm including this because making this possible was in fact in large part a side-effect of the 2nd wish:
2- allow the use of privileged services via the system bus, for instance those based on the KF5 KAuth framework.
With hindsight, point 2 was very easy to implement because the the mechanism to launch the privileged service executable is works as intended on OS X. What failed was the basic libdbus initialisation in the service executable, which didn't provide a session bus address entry in the bus_connection_addresses array.
Given the context the exact value of that entry is without importance. On Linux it would be set to "autolaunch:"; in the attached patch I set it to "launchd:env=DBUS_LAUNCHD_SESSION_BUS_SOCKET" because that appears to be an existing convention. Enabling the code path that takes care of setting this fallback value is what made it relevant to include point 1 above.
There are a few points that are open to discussion:
is "launchd:env=FOO" indeed an appropriate fallback address? I don't think it will ever be used but may overlook a borderline situation.
should the org.freedesktop.dbus-system.plist launchd profile provided by my patch be installed by default or should it be optional or an operation to be done manually? Note that installing it doesn't load profile.
should _dbus_lookup_launchd_socket() indeed check the value of DBUS_LAUNCHD_SESSION_BUS_SOCKET in the environment, and if so should that value have priority over the value obtained from launchctl? The intention I had with the addition was to give a similar mechanism to override the "default" session bus as can be achieved on Linux by overriding DBUS_SESSION_BUS_ADDRESS. NB: changing the DBUS_LAUNCHD_SESSION_BUS_SOCKET value via launchctl has an immediate session-wide effect.
Version: git master