[systemd-devel] How do I hook into ACPI events?
Mantas Mikulėnas
grawity at gmail.com
Fri May 27 04:56:10 UTC 2016
On Fri, May 27, 2016 at 12:12 AM, Mason Loring Bliss <mason at blisses.org>
wrote:
> Traditionally I could edit scripts in /etc/acpi to accomplish things, but
> on
> EL7 I'm seeing that some combination of upower and systemd/logind appear to
> be the way to control responses to ACPI events.
>
> I want to have custom things happen on lid close, and I'm not seeing how to
> accomplish it as yet.
>
> logind.conf(5) and the web page at
> https://www.freedesktop.org/software/systemd/man/logind.conf.html both
> enumerate the options for HandleLidSwitch:
>
> Can be one of "ignore", "poweroff", "reboot", "halt", "kexec",
> "suspend", "hibernate", "hybrid-sleep", and "lock". If "ignore", logind
> will never handle these keys.
>
> I thought at first kexec was a way I might hook in behaviour, but now I see
> that kexec is for fast reboots. Nothing else seems appropriate there.
>
> How can I do this? The default RHEL7 Gnome seems to be able to inject
> custom
> behaviour, as it locks the screen on lid close before sleep, but it's not
> yet
> clear how they do it.
~ The primary method is: take a {sleep, delay} inhibitor, wait for a
"PrepareForSleep" signal via D-Bus, and drop the inhibitor when done with
the preparations. That's what desktop environments (e.g. GNOME) use for
locking the screen, and it's what system daemons (e.g. NM) use for pausing
connections and making other preparations; it's going to be the best choice
if your plans involve $DISPLAY in any way at all. There was a thread just a
few days earlier about doing this via Perl's Net::DBus.
~ At *system* level (no X11), If all you need is to run some rmmod/modprobe
(ick), then systemd-sleep(8) hooks would be simplest. They run immediately
before systemd tells the kernel to suspend, and immediately after.
~ If you need something more complex, but still at system level (e.g.
ponies and rainbows instead of suspending), then acpid will still work. You
can set HandleLidSwitch=ignore, install acpid, and use your old /etc/acpi
handler scripts, manually calling `systemctl suspend` at the end.
~ Finally, if you're writing a *desktop environment*, you can take a
{handle-lid-switch, block} inhibitor, which signals logind that you want to
[temporarily] completely take over the lid-switch handling; then you can
receive ACPI events directly via X11, or from /dev/input, or from netlink,
or from acpid, or whatever. That's what KDE and Xfce do. GNOME doesn't
handle the lid, but still takes over the power button this way.
(I frequently abuse the above via "systemd-inhibit --what=handle-lid-switch
/bin/sleep 1h" as a quick way to temporarily disable sleep-on-close.)
--
Mantas Mikulėnas <grawity at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20160527/5ccb81a6/attachment.html>
More information about the systemd-devel
mailing list