I am not sure what exactly makes my setup peculiar but godbus cannot discover the desktop session bus and ends up creating its own session which is not useful at all.
Details of the system:
- FreeBSD 14
- lightdm as a DM
- X11-based KDE Plasma desktop
- startplasma-x11 is used to start Plasma
Why godbus fails to discover the session bus:
- nothing D-Bus related in environment (like
DBUS_SESSION_BUS_ADDRESS)
- there is no /run/user/... directory at all (because this is FreeBSD?)
- there is /var/run/user/... but there is no 'bus' file / socket in it;
- there is no 'dbus-session' file either
- godbus does not check for it but there is ~/.dbus/session-bus, still nothing useful in it
So, how does everything else (using libdbus C library) work?
Turns out that there is yet another way to discover a D-Bus session in X-based environment.
The code can be found in https://gitlab.freedesktop.org/dbus/dbus/-/blob/main/tools/dbus-launch-x11.c?ref_type=heads
See x11_get_address().
TLDR: there is a special window that has _DBUS_SESSION_BUS_ADDRESS X property set on it.
Querying the property is easy, e.g.:
$ xprop -id 14680065 _DBUS_SESSION_BUS_ADDRESS
_DBUS_SESSION_BUS_ADDRESS(STRING) = "unix:path=/tmp/dbus-WIQOSbbQmm,guid=cbe363fc117423c16e01bf6a6824260c"
But discovering the window requires using XGetSelectionOwner function from Xlib / libX.
There is also a way to discover that address using dbus-launch --autolaunch=<MACHINEID> command.
MACHINEID can be obtained from /var/lib/dbus/machine-id file (at least, in my environment).
--autolaunch is documented to be "considered an internal implementation detail of libdbus".
But godbus is a Golang re-implementation of libdbus, so using that option would not be inappropriate, IMO.
I do not have a concrete suggestion on a fix.
Maybe my setup is too uncommon.
But I think that covering all capabilities of the original D-Bus implementation would be a worthy pursuit.
I am not sure what exactly makes my setup peculiar but godbus cannot discover the desktop session bus and ends up creating its own session which is not useful at all.
Details of the system:
Why godbus fails to discover the session bus:
DBUS_SESSION_BUS_ADDRESS)So, how does everything else (using libdbus C library) work?
Turns out that there is yet another way to discover a D-Bus session in X-based environment.
The code can be found in https://gitlab.freedesktop.org/dbus/dbus/-/blob/main/tools/dbus-launch-x11.c?ref_type=heads
See
x11_get_address().TLDR: there is a special window that has
_DBUS_SESSION_BUS_ADDRESSX property set on it.Querying the property is easy, e.g.:
But discovering the window requires using
XGetSelectionOwnerfunction from Xlib / libX.There is also a way to discover that address using
dbus-launch --autolaunch=<MACHINEID>command.MACHINEID can be obtained from /var/lib/dbus/machine-id file (at least, in my environment).
--autolaunch is documented to be "considered an internal implementation detail of libdbus".
But godbus is a Golang re-implementation of libdbus, so using that option would not be inappropriate, IMO.
I do not have a concrete suggestion on a fix.
Maybe my setup is too uncommon.
But I think that covering all capabilities of the original D-Bus implementation would be a worthy pursuit.