"godbus" trouble connecting to system bus

raspberrypi3
network

#1

Greetings,

I’m attempting to interact with DBUS from a Go application. I’m using the godbus library to handle the communication. I’m unable to connect to the system bus. I receive the following error:

2018/01/29 18:29:26 Unable to connect to systembus: dial unix unix:path=/host/run/dbus/system_bus_socket: connect: no such file or directory

Here is a snippet of the code:

// get a bus connection
	connection, err := dbus.SystemBus()
	if err != nil {
		log.Fatalf("Unable to connect to systembus: %v", err)
	}

In my DOCKERFILE, I have:

FROM resin/%%RESIN_MACHINE_NAME%%-golang:slim
ENV INITSYSTEM on
ENV DBUS_SYSTEM_BUS_ADDRESS unix:path=/host/run/dbus/system_bus_socket

RUN apt-get update && apt-get install -yq dbus

RUN go get github.com/godbus/dbus
… application specific stuff

I have verified via printenv | grep dbus that the environment variable is properly set. To be triply sure, I’ve exported the environment variable in my container before running the Go script that connects to dbus. I’ve also checked the directory /host/run/dbus/ and have verified a socket file entitled system_bus_socket.

To further debug, I installed the dbus package in my container and ran a sample command to see if things would work:

DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket
dbus-send
–system
–print-reply
–reply-timeout=2000
–type=method_call
–dest=org.freedesktop.timedate1
/org/freedesktop/timedate1
org.freedesktop.DBus.Properties.GetAll
string:“org.freedesktop.timedate1”

I received a response back that matched what was expressed in “Container Runtime” resin page (having trouble linking…).
I’m pretty sure it’s a valid test case because of the BUS_ADDRESS export, but I’m not super experienced with dbus to know for sure.

System Information
Host OS: Resin OS 2.7.8+rev1 (dev)
Supervisor: 6.4.2

Any help is appreciated.

Thanks!


#7

Well, after diving through the source code of godbus, I have found that the code is adding part of the path that is already exported in the environment variable: https://github.com/godbus/dbus/blob/8a466719ecfaf26ae3d712084f3da9bfcae0fdd2/conn_other.go#L39

By changing my environment variable to:

ENV DBUS_SYSTEM_BUS_ADDRESS /host/run/dbus/system_bus_socket

I get past that part of the execution. I’m now getting segfaults, but I’m at least getting the connection proper!

Hopefully this helps someone in the future.


#9

Thanks for updating the thread with the eventual resolution. :sparkles: