Linux – How Do Desktop Environments Call ACPI Functions

consolekitlinuxnot-root-userprivilegesshutdown

Okay, first off, this is not a problem I am facing, but I would like to understand this better.

If I wish to shutdown / reboot my machine from the command line I need to call:

$ sudo poweroff
$ sudo reboot

That is, I need root privileges to make these ACPI calls.

However, I start my DE, (I use XFCE) without granting it root privileges:
$ startxfce4 –with-ck-launch

Now, I know that the --with-ck-launch parameter helps allows XFCE to shutdown / reboot my system, but I do not understand how.

What allows ConsoleKit to shutdown without root privileges? How can it change the runlevel without super-user privileges? And since it is possible, how can I shutdown my machine from the console without root privileges?

Best Answer

You can communicate with ConsoleKit through dbus. For example using the dbus-send tool a few notable commands are,

Shutdown:

dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop

Reboot:

dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Restart

There are also commands for hibernate and suspend but I do not know what they are.


edit: Found suspend command

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

On newwer systems

dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Suspend
Related Question