[systemd-devel] Having systemd shutdown when pressing the power button

Lennart Poettering lennart at poettering.net
Thu Aug 28 06:42:53 PDT 2014

On Thu, 28.08.14 10:50, Koen Kooi (koen at dominion.thruhere.net) wrote:

> Hi,


> I am working on a system (http://www.acmesystems.it/arietta) where I
> hooked up the button as a power key:
> 	https://github.com/koenkooi/linux/commit/c823e0b046efcfff61e21fa4c89d5d68090ef6de
> Evtest shows it doing the right thing (issuing KEY_POWER) when being
> pressed, but systemd seems to totally ignore it. I've seen this
> behaviour in the past and noticed the DE (GNOME2, old but it works)
> would pick it up and present the dialog. Since this is a headless
> system I want systemd to handle it instead of the DE (which isn't
> installed).  Every doc or blog post I read says that systemd should
> already be handling it, but it isn't in my case. I suspect that
> systemd only handles ACPI powerkey events, but I haven't actually
> looked at the code.
> Are more people experiencing this and does someone have a workaround
> or fix?

You have to tag your input devices with the "power-switch" udev tag,
otherwise logind won't pick up the device.

See 70-power-switch.rules for the current default:

        SUBSYSTEM=="input", KERNEL=="event*", SUBSYSTEMS=="acpi", TAG+="power-switch"
        SUBSYSTEM=="input", KERNEL=="event*", KERNELS=="thinkpad_acpi", TAG+="power-switch"

I'd really like to open this up, to be done on all kbds by default, but
I feel uneasy about listening to all keypresses on all keyboards by
default.... We don't want that logind is woken up on virtually *all*
keypresses on the entire system, all the time.

David Hermann did a kernel patch to improve the situation:


With this in place, userspace can set a mask of input keys it is
interested in, and we could use that for logind to just subscribe to
power keypresses and be happy...

Unfortunately though the patch got repeatedly ignored by the input
maintainers, even though it got resent multiple times... :-(


Lennart Poettering, Red Hat

More information about the systemd-devel mailing list