11
votes

Hello Dear SO Community :)

I am trying to get DBus working on my Raspberry Pi. The example code from libdbus-c++-1 is working fine when i am in the Pi Desktop environment -> (startx)

My researches on the internet and the examples i found on stackoverflow didnt help me :[.

However, when i am in the Shell-Mode i get the error message

./client
terminate called after throwing an instance of 'DBus::Error'
  what():  /usr/bin/dbus-launch terminated abnormally with the following error: Autolaunch error: X11 initialization failed.
Aborted

i also tried

eval 'dbus-launch --auto-syntax' ./client

eval 'dbus-launch --auto-syntax' ./server

but it does not work, the server app is starting a message daemon but it is not reachable from the client. Also the daemon stays active.

i got:

terminate called after throwing an instance of 'DBus::Error'
  what():  The name org.freedesktop.DBus.Examples.Echo was not provided by any .service files
call1: Aborted

also it does not shown in the services list.

after this i tried another command

DISPLAY=":0" DBUS_SESSION_BUS_ADDRESS="unix:path=/run/dbus/system_bus_socket" ./server

and i got:

terminate called after throwing an instance of 'DBus::Error'
  what():  Connection ":1.10" is not allowed to own the service "org.freedesktop.DBus.Examples.Echo" due to security policies in the configuration file
Aborted

:( after that is also not working i found a way to compile the dbus without the X11 Code with

./configure --with-x=no

unfortunately it has no effect. Still require X11 to start my applications... What do i wrong?

but commands like

eval 'dbus-launch --auto-syntax' dbus-monitor

How can i start my applications without starting X11 i dont need it and i dont want it. Thank you for your help and time.

kindly regards oOm

#

Update i feel a bit silly now but i found a way to run it without the x11

first you need to start a dbus session daemon

dbus-launch

this will prompt you your DBUS_SESSION_BUS_ADRESS

DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-9rMVHdByuH,guid=10592ff7107f13dd241a02af531ab357
DBUS_SESSION_BUS_PID=2465

after that you can launch your c++ application like this

DBUS_SESSION_BUS_ADDRESS="unix:abstract=/tmp/dbus-9rMVHdByuH,guid=10592ff7107f13dd241a02af531ab357" ./server

you can registered services with

DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-6aT4DZgmA1,guid=b1231a014a7b10e74e04f8ba531abdf9 dbus-send --session --dest=org.freedesktop.DBus   --type=method_call --print-reply                 /org/freedesktop/DBus org.freedesktop.DBus.ListNames

and monitoring the messages with

DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-6aT4DZgmA1,guid=b1231a014a7b10e74e04f8ba531abdf9 dbus-monitor

but one question is left, how can i do it automatically?

2
Sorry for the long Post :)Dogan
Hello Dogan I ended up on your page for I am having similar issue on raspberry pi. dbus-launch command is not found on raspberry pi, I have a headless installation of pi with no X server. How to get dbus-launch package ??Ahmed

2 Answers

0
votes

Great post. You obviously had more diligence than I; I ended up running a display buffer instead.

but one question is left, how can i do it automatically?

Since

$dbus-launch 

outputs the bus info to standard out, did you try just running the program after? For instance

$dbus-launch ./server

The dbus-launch man page says:

You may specify a program to be run; in this case, dbus-launch will launch a session bus instance, set the appropriate environment variables so the specified program can find the bus, and then execute the specified program, with the specified arguments. See below for examples.

If you launch a program, dbus-launch will not print the information about the new bus to standard output.

0
votes

but one question is left, how can i do it automatically?

take a look at dbus-launch manual:

backticks or the $() construct can be used to read information from dbus-launch.