Skip to content

D-Bus

A tested inter process communication construct. There is no tutorial that just explains it as it is.

This one comes closest : visit

On a Linux workstation you normally get 2 types if Bus's. The system bus, used for system processes, and a session bus that get's started when you log in to the x server. You can use d-feet to show you the connections on each bus, and you can clearly see at the top there us a System bus and a Session Bus.

install d-feet
apt-get install d-feet
d-feet

But if you do not have an Xsession, you can't start up d-feet. You can however list them with these very simple python programs.

example
1
2
3
import dbus
for service in dbus.SystemBus().list_names():
    print(service)

There is a command line tool dbus-send as well, but if you view the syntax, I prefer the python version:

send
1
2
3
4
5
6
7
dbus-send --session           \
    --dest=org.freedesktop.DBus \
    --type=method_call          \
    --print-reply               \
    /org/freedesktop/DBus       \
    org.freedesktop.DBus.ListNames
    System:

Now if you try both scripts on a headless workstation or server you will find that the systembus works, but the session bus says:

exception
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NotSupported: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11

So it seems there is some sort of automatic launching involved when you run an xserver. But we can start one manually with this command :

start
1
2
3
4
dbus-run-session bash
python session.py
org.freedesktop.DBus
:1.0

This lists a lot less than on an xserver, but hey we just started it. Outside this bash session we still cannot run the session list script, so it would be nice to start a session like under the X server. In the package dbus-x11 there is a tool that can do that.

dbus-x11
apt-get install dbus-x11
dbus-launch

It spits out a lot of info, which you must save, or directly activate in other sessions.

set session variables
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-2VWFgZRqqV,guid=5526d35007ae13d38ede29a05c065daf
DBUS_SESSION_BUS_PID=4392

These are formatted as environment variables, so try and apply them to all windows you want to use, the DBUS_SESSION_BUS_ADDRESS seems to do the trick already, but maybe the other one is needed somewhere else so apply both :

set session variables
1
2
3
export DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-2VWFgZRqqV,guid=5526d35007ae13d38ede29a05c065daf
export DBUS_SESSION_BUS_PID=4392
python system.py

There is a C example on this site : visit For a hands on example, that works Ok to refresh your memory.

See keyring for some more d-bus usage.