Using DBUS to send command

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)
}

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.

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.

Any update on this?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.