How to export DBUS_SESSION_BUS_ADDRESS

58.3k views Asked by At

I'm trying to run D-Bus on an embedded system (Yocto Linux) and connect to it from my application code.

I get the following error when I call dbus_bus_get(DBUS_BUS_SESSION, &err);

Using X11 for dbus-daemon autolaunch was disabled 
at compile time, set your DBUS_SESSION_BUS_ADDRESS 
instead

I realize that I need to start the dbus-daemon first so I have run dbus-launch from the command line.

This prints out a value of DBUS_SESSION_BUS_ADDRESS but how could I export it programmatically?

6

There are 6 answers

3
User55412 On BEST ANSWER

I've finally found the answer, running the following command exports the output of dbus-launch:

export $(dbus-launch)
2
Syfi Malik On

Type in terminal:

export $DBUS_SESSION_BUS_ADDRESS
0
ernobe On

It sounds like you are trying to get the value of DBUS_SESSION_BUS_ADDRESS in order for your application to run correctly. Try running it with dbus-run-session instead of dbus-launch. According to https://dbus.freedesktop.org/doc/dbus-launch.1.html dbus-launch should not be run from the command line, but in a shell script (see also https://dbus.freedesktop.org/doc/dbus-run-session.1.html).

3
Mostafa Aghashahi On

Type the following command into a terminal:

eval `dbus-launch --auto-syntax`
2
user3801989 On
pid_gnome=$(pgrep gnome-session)
DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/${pid_gnome}/environ|cut -d= -f2-)
export DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS}

Please make sure that the user has the DISPLAY variable set.

Another alternative is:

export $(dbus-launch)
0
JonGreen On

When you launch your user session, do it like this:

dbus-daemon --session --fork --print-address 1 > /tmp/dbus-session-addr.txt

This will cause the session address to be written to /tmp/dbus-session-addr.txt. (The filename's not that important, it's just somewhere you've decided to store it.)

Then, when you need the variable set:

export DBUS_SESSION_BUS_ADDRESS=$(cat /tmp/dbus-session-addr.txt)

If your shell's sniffy about export-during-definition - some can be - do it in two stages:

DBUS_SESSION_BUS_ADDRESS=$(cat /tmp/dbus-session-addr.txt)
export DBUS_SESSION_BUS_ADDRESS