Skip to content

Use the existing user D-Bus session ($XDG_RUNTIME_DIR/bus) instead of spawning dbus-launch #210

Description

@Fantu

Issue

require_dbus_session() in cinnamon-session/main.c only checks the
DBUS_SESSION_BUS_ADDRESS environment variable: if it is unset, it re-execs
itself under dbus-launch --exit-with-session, even when a user D-Bus session
bus is already running at $XDG_RUNTIME_DIR/bus (the default on any systemd
system, and also with elogind + dbus configured for the user bus).

This spawns a second session bus, separate from the user bus: D-Bus
activated services and portals end up split across the two buses. On systems
without the dbus-launch binary (Debian with only dbus-user-session
installed) the session fails to start entirely.

X11 logins are usually unaffected because display managers wrap the session
with a script that exports DBUS_SESSION_BUS_ADDRESS (e.g.
/etc/X11/Xsession.d/20dbus_xdg-runtime on Debian-based distros). But the
Wayland session (cinnamon-session-cinnamon --wayland) does not go through
those wrappers, so whether the fallback triggers depends on the display
manager. It is also easy to demonstrate directly:

$ env -u DBUS_SESSION_BUS_ADDRESS cinnamon-session --version

re-execs under dbus-launch and spawns a new dbus-daemon --session just to
print the version.

Suggested fix

Do what current gnome-session does (gnome-session/leader-main.c): ask GDBus
for the session bus address before falling back to dbus-launch. GDBus already
falls back to $XDG_RUNTIME_DIR/bus when the variable is unset (GLib >= 2.50):

address = g_dbus_address_get_for_bus_sync (G_BUS_TYPE_SESSION, NULL, NULL);
if (address != NULL) {
        g_setenv ("DBUS_SESSION_BUS_ADDRESS", address, TRUE);
        return TRUE;
}
/* existing dbus-launch fallback for non-systemd/non-elogind setups */

Exporting the variable keeps every child process of the session on the same
bus. The dbus-launch path would remain as a last resort, so nothing changes
for setups without a user bus.

Originally reported in Debian in 2016 as part of a cross-desktop effort to
reduce reliance on dbus-launch: https://bugs.debian.org/835846 (gnome-session
dropped dbus-launch entirely; the check described there — a socket at
$XDG_RUNTIME_DIR/bus owned by the current uid — is what the GDBus call
implements).

I can send a PR if this approach is acceptable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions