Accessing dbus services in docker daemon code

I’m working on a custom extension for the docker daemon which relies on accessing an external service through dbus. As far as I can tell, putting this code into components/engine/daemon.containerCreate should work:

conn, err := dbus.SystemBus()
if err != nil { fmt.Printf("Failed to connect to system bus: %v\n", err); return errors.New("Failed"); }
obj := conn.Object(objectBus, objectPath)
call := obj.Call(methodName, 0)
if call.Err != nil { fmt.Printf("Failed to call dbus method: %v\n", err); return errors.New("Failed"); }

But this always produces the output, Failed to call dbus method: dbus: connection closed by user. Building exactly the same code into a standalone executable works correctly.

I’ve also tried using dbus.SystemBusPrivate but then the method call hangs.

Has anyone developing docker seen this? Is there some trick to getting dbus to work?

Just to note that I’ve got SystemBusPrivate() working - it doesn’t prepare the connection in the same way as SystemBus() does, you need to call Auth(nil) and Hello() on it before it can be used. I’m still not sure why the shared system bus doesn’t work - either something in docker is explicitly closing it, or a bus error is causing it to be closed.