Skip to content

dbus-launch: Generalize support for discovering an existing bus

Simon McVittie requested to merge smcv/dbus:generalize-autolaunch into master
  • dbus-launch: Generalize support for discovering an existing bus

    Previously we were looking for an existing bus via _dbus_lookup_user_bus(), meaning a user bus $XDG_RUNTIME_DIR/bus (in practice this is managed by systemd --user, although in principle there's nothing to stop other session frameworks from providing the same thing).

    _dbus_lookup_session_address() looks for an externally-managed dbus-daemon in a more general way: on macOS it uses launchd, and on other Unix it's a thin wrapper around _dbus_lookup_user_bus(). Let's try that, so that macOS users can get their existing dbus-daemon from launchd.

    This partially resolves #385 (closed), although initially only for macOS users who have (unusually) enabled X11 autolaunching support.

  • dbus-launch: If no X11, look for existing bus before failing

    What we are aiming for here is that dbus-launch --autolaunch will exit with an error if it would have been unable to advertise the bus in a way that will be picked up by other instances of itself, so that we don't get a proliferation of autolaunched dbus-launch instances, each with its own dbus-daemon, and none of them talking to the others.

    However, we don't need to do that immediately: we can try to look for an existing instance first. If we find one, then we can assume that it's suitable for use, even if X11 autolaunching was disabled at compile-time or if connecting to the X server failed at runtime. We only need to bail out if we get to the point where we are ready to start forking child processes.

    This lets systemd users run dbus-launch --autolaunch to find a systemd-managed dbus-daemon, even if X11 autolaunching is disabled. When combined with the previous commit, it also lets macOS users run dbus-launch --autolaunch to find a launchd-managed dbus-daemon.

Merge request reports