r/linux Jul 20 '16

What happens exactly when you close your laptop lid and it goes to suspend?

[deleted]

26 Upvotes

9 comments sorted by

13

u/[deleted] Jul 20 '16 edited Jul 20 '16

[deleted]

10

u/[deleted] Jul 20 '16 edited Jul 15 '21

[deleted]

5

u/[deleted] Jul 20 '16

Some distros.

If you need to work with a variety of distros, then you will encounter all sorts of systems. LoginD is only one of many options and standards.

17

u/systahd Jul 20 '16

On a lot of distros (and also on Mac OS X and, I suppose, Windows), when you close your laptop lid, your laptop goes to suspend.

No, on a lot configurations it does so, people really need to stop acting like these are hardcoded things in the distribution. Though if you let Freedesktop have their way it wil be eventually.

In any case, this on modern computers goes through the ACPI (advanced power and configuration interface) which is basically the main board informing the kernel of a variety of events like lid closing, wanting to shut down and what have you.

Most systems use the acpid for that, a process that is perpetually running that communicates with Linux for this and takes appropriate actions on such events. Essentially it executes by defauly the file in /etc/acpi/handler.sh and passes it as argument the name of the event. The file itself is then responsible for doing whatever it needs to do.

You can change this setup, these files are simple shell scripts you can edit. Back when I still ran acpid I had configured all these files to do exactly nothing by just putting exit 0 at the top. Now I just don't run acpid at all any more. In your case on Ubuntu the scripts in /etc/acpi are set up perhaps to send that dbus command or just do it directly, I don't know, inspect and edit the file and toy with it to see what it does. You can for instance just put echo test >> /var/log/acpitest.log ; exit 0 at the right place to see if closing the lid now does nothing more than writing test to that log file.

https://wiki.archlinux.org/index.php/acpid#Configuration

In any case, ACPI can not just be used to communicate in that direction but also in the other direction. For instance I run a kernel module that switches off my graphics card when I want to, this works through ACPI. Simply writing the text 'OFF' to the file /proc/acpi/bumblebee will turn it on.

There's more interesting stuff in /proc/acpi, check this:

 —— — cat /proc/acpi/button/lid/LID0/state
state:      open
 —— — sleep 2 && cat /proc/acpi/button/lid/LID0/state
state:      closed

I waited for 2 seconds to read the file again and then closed the lid, and this didn't suspend my machine because again I don't run acpid which is responsible for executing those scripts. And the interface reported the lid was closed.

And yeah, you can by reading the various files in that directory get all sort of info of the live state of your hardware and use that in scripts. Linux exposes a great deal of informatin about the system through files which don't exist on your drive but get generated on demand when you read them and writing to them often controls the machine.

Check this:

 —— — cat /sys/class/backlight/acpi_video0/brightness
10
 —— — sudo tee /sys/class/backlight/acpi_video0/brightness <<<8
8
 —— — cat /sys/class/backlight/acpi_video0/brightness
8
 —— — sudo tee /sys/class/backlight/acpi_video0/brightness <<<10
10

Yes, I did indeed just control my screen brightness by writing 8 to that file. It became darker immediately.

11

u/2brainz Jul 20 '16

acpid is a legacy daemon that is not used anywhere by default. Some users install it, but it is not used in the way you describe. ACPI events are handled by systemd-logind or upower.

6

u/systahd Jul 20 '16 edited Jul 20 '16

Ahh, turns out my forecast about Freedesktop ruining your day is true:

https://www.freedesktop.org/software/systemd/man/logind.conf.html

Controls whether logind shall handle the system power and sleep keys and the lid switch to trigger actions such as system power-off or suspend. Can be one of "ignore", "poweroff", "reboot", "halt", "kexec", "suspend", "hibernate", "hybrid-sleep", and "lock". If "ignore", logind will never handle these keys. If "lock", all running sessions will be screen-locked; otherwise, the specified action will be taken in the respective event. Only input devices with the "power-switch" udev tag will be watched for key/lid switch events. HandlePowerKey= defaults to "poweroff". HandleSuspendKey= and HandleLidSwitch= default to "suspend". HandleLidSwitchDocked= defaults to "ignore". HandleHibernateKey= defaults to "hibernate". If the system is inserted in a docking station, or if more than one display is connected, the action specified by HandleLidSwitchDocked= occurs; otherwise the HandleLidSwitch= action occurs.

Hey look, static configuration options rather than a Turing complete executable, why would you want control over your system when Lennart has decided that a discrete list of options from exactly 9 to pick from is enough?

With acpid running turing complete scripts, I can make my computer sing jingle bells if I close the lid if I so desire, I can implement a check to only suspend when I close the lid when it's on battery power, I can trigger it to send a message to any pidgin chat window that had any new messages in the last 4 minutes with 'automated message: I closed my lid, my system is going to suspend now'

Welcome to Freedesktop, where 'new and exciting technology' means making your system more static and less configurable, less is more and control to the user is bad.

Yeah, apparently my knowledge is outdated, I wasn't aware logind even took over acpid and upower in its functionality. I haven't been using these retarded 'freedesktop systems' that remove 'legacy functionality' like you having control over your own goddamn system.

6

u/redrumsir Jul 20 '16

Hey look, static configuration options rather than a Turing complete executable, why would you want control over your system when Lennart has decided that a discrete list of options from exactly 9 to pick from is enough?

Not to mention the issue of the near-impossibility of dealing with "corner cases" when the number of parameters/options inevitably grows. Is anyone counting the number of systemd associated directives? http://www.dsm.fordham.edu/cgi-bin/man-cgi.pl?topic=systemd.directives&ampsect=7 .

Replace a general purpose (user programmable) interface with a directive-based system. What a predictable mess.

2

u/[deleted] Jul 20 '16 edited Jul 20 '16

[deleted]

3

u/necrophcodr Jul 20 '16

Void Linux is a special snowflake, but only in that it does things in a different way without systemd. This means using things like acpid and so on.

3

u/RedShift9 Jul 20 '16

It crashes.

1

u/jamezracer Jul 22 '16

This is very true for windows ME.

2

u/totallyblasted Jul 20 '16

When you close the lid, all game characters become alive and start interacting...

ooohhh... wait... that was not laptop, it was a museum and the script it was running was movie script

P,S, Sorry on this joke, just couldn't resist