4

What is the command or application that allows a user to shutdown the computer from gnome. And how does it have privileges while halt requires superuser?

2

It uses a DBus message.

dbus-send --system --print-reply --dest=org.freedesktop.Hal \
          /org/freedesktop/Hal/devices/computer \
          org.freedesktop.Hal.Device.SystemPowerManagement.Shutdown

Found this here.

Reboot:

dbus-send --system --print-reply --dest=org.freedesktop.Hal \
          /org/freedesktop/Hal/devices/computer \
          org.freedesktop.Hal.Device.SystemPowerManagement.Reboot

Suspend:

dbus-send --system --print-reply --dest=org.freedesktop.Hal \
          /org/freedesktop/Hal/devices/computer \
          org.freedesktop.Hal.Device.SystemPowerManagement.Suspend int32:1

Hibernate:

dbus-send --system --print-reply --dest=org.freedesktop.Hal \
          /org/freedesktop/Hal/devices/computer \
          org.freedesktop.Hal.Device.SystemPowerManagement.Hibernate
3
  • So dbus-send doesnt require root privileges?, and what is dbus?
    – agz
    Jan 13 '13 at 19:25
  • 1
    DBus allows multiple applications to communicate together. And no, dbus-send does not require root to be used. DBus is owned by root too.
    – user183714
    Jan 13 '13 at 19:31
  • 2
    Downvoted because HAL has been obsolete for about 4 years. Recent Ubuntus use either UPower or ConsoleKit for this, or possibly even Upstart directly.
    – user1686
    Jan 13 '13 at 21:23
2

GNOME does this by sending messages over DBus to a service which already runs as root.

To shutdown or reboot using ConsoleKit:

gdbus call -y -d org.freedesktop.ConsoleKit \
              -o /org/freedesktop/ConsoleKit/Manager \
              -m org.freedesktop.ConsoleKit.Manager.Stop
gdbus call -y -d org.freedesktop.ConsoleKit \
              -o /org/freedesktop/ConsoleKit/Manager \
              -m org.freedesktop.ConsoleKit.Manager.Restart

To suspend or hibernate using UPower:

gdbus call -y -d org.freedesktop.UPower \
              -o /org/freedesktop/UPower \
              -m org.freedesktop.UPower.Suspend
gdbus call -y -d org.freedesktop.UPower \
              -o /org/freedesktop/UPower \
              -m org.freedesktop.UPower.Hibernate

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.