Using DBUS to send command


(Casey) #1

I am trying to use https://godoc.org/github.com/godbus/dbus to send a command to reboot the system from my code.

I can’t seem to get it to send correctly.
With typical dbus i could send: “dbus-send --system --print-reply --dest=org.freedesktop.login1 /org/freedesktop/login1 “org.freedesktop.login1.Manager.Reboot” boolean:true”

I am trying to achieve the same as that command but with godbus. Here’s my code:
conn, err := dbus.SystemBus()
if err != nil {
panic(err)
}

conn.Emit("/org/freedesktop/login1", "org.freedesktop.login1.Manager.Reboot", "boolean:'true'")
if err != nil {
	fmt.Println(err)
}

(Norbert Melzer) #2

I’m not using it, but from the docs it looks like the emit should look like conn.Emit("/org/freedesktop/login1", "org.freedesktop.login1.Manager.Reboot", true).

If that doesn’t work, please tell us the error message you get when printing err.


(Casey) #3

I tried it as you wrote. The program runs and then exits. No error is printed.

conn, err := dbus.SessionBus()
if err != nil {
	panic(err)
}

err = conn.Emit("/org/freedesktop/login1", "org.freedesktop.login1.Manager.Reboot", true)
if err != nil {
	fmt.Println(err)
}

Tried it with both SessionBus and SystemBus. No error in either.


(Casey) #4

Any update on this?