D-Bus

From Alpine Linux
Revision as of 19:05, 27 October 2023 by Sertonix (talk | contribs) (add actual installation instructions)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

D-Bus is a message bus system that provides a mechanism for inter-process communication.

Some services rely on a D-Bus session instance or expect it by default (including Pipewire). Other processes will only be able to communicate with these services if d-bus is running.

Installation

Install the dbus package:

# apk add dbus

If you are using x11 you might also want to install the X11 add-ons which provide the dbus-launch command:

# apk add dbus-x11

If you want dbus to be started at system startup enable the service:

# rc-update add dbus

To use the service without restarting you need to start it manually:

# rc-service dbus start

Note: This only starts the system dbus. The dbus session is started separatly for each user.

D-Bus session

You can start a dbus session like this: dbus-run-session -- sh(replacing sh with your shell or a window manager), or, export $(dbus-launch).

D-Bus passes the environment variable $DBUS_SESSION_BUS_ADDRESS to its children. Running dbus-launch in a terminal means that other running process won't find this D-Bus's socket.

If $DBUS_SESSION_BUS_ADDRESS is undefined, many applications will attempt to use the standard path:

$XDG_RUNTIME_DIR/bus

Running D-Bus like so should work for many applications:

dbus-daemon --nofork --address unix:path=$XDG_RUNTIME_DIR/bus --session


For applications that dont work without $DBUS_SESSION_BUS_ADDRESS you can prepend your program with the follow workaround script which avoid launching multiple user dbus sessions:

#!/bin/sh
if [ ! -e "/tmp/dbus-$USER-env" ]; then
       echo "Creating new dbus session on /tmp/dbus-$USER-env"
       export $(dbus-launch)
       echo "${DBUS_SESSION_BUS_ADDRESS}" > /tmp/dbus-$USER-env
       echo "Dbus session address is: ${DBUS_SESSION_BUS_ADDRESS}"
else
       echo "Using dbus session address from /tmp/dbus-$USER-env"
       export DBUS_SESSION_BUS_ADDRESS="$(cat /tmp/dbus-$USER-env)"
       echo "Dbus session address is: ${DBUS_SESSION_BUS_ADDRESS}"
fi
if [ -n "$1" ]; then
       $@
fi

See also