Intro #
London, a sunny Sunday, 11 am. I’m two sips into my first iced latte, my trusty ThinkPad T14 Gen1 is planted on one of those small round wooden coffee tables.
The Plan: spin up a GitHub repo and develop a small bot to help with a few annoying tasks I encounter from time to time and get some “I am productive in a Café”-smugness.
Mid-typing suddenly I get SNAP, and instead of admiring my brand-new repo, I’m suddenly staring at the black screen of my ThinkPad, where a very confused cybersecurity professional is reflected back at me.
I have met this instant narcolepsy before. But always just shrugged it off and mashed the power button. Hoping this is just a one-time weirdness.
Today, with the caffeine already starting to kick in, is not the day for this issue to be shrugged off. Time to drag this mystery into daylight. While mentally already preparing to have to physically fix something or buy a new ThinkPad, I start to investigate.
A quick look at the usual Suspects #
Checkpoint | What we’re verifying | Result |
---|---|---|
KDE power settings | Check that suspend times and everything is set to reasonable values | “looks good so far” |
BIOS / Firmware | System on latest firmware & everything up to date | BIOS & Firmware on newest available versions |
BIOS sleep state | Make sure the BIOS sleep state API that gets exposed is set to Linux |
✅ |
Everything looks good so far, so why is my laptop faceplanting :/?
Enter the Dungeon Journal
#
Let’s ask our trusty journalctl
what the hell was going on.
journalctl -u systemd-logind --since "1 hour ago"
With the command above we can inspect the log messages that were emitted by the systemd-logind
service in the last hour. This service is responsible for all user logins and their adjacent user sessions. So when your Laptop goes to sleep, you can see it here.
Now for me, the command above yielded the following output.
Jul 13 11:03:53 <hostname> systemd-logind[<pid>]: Lid closed.
Jul 13 11:03:54 <hostname> systemd-logind[<pid>]: The system will suspend now!
Jul 13 11:03:54 <hostname> systemd-logind[<pid>]: Lid opened.
Jul 13 11:04:17 <hostname> systemd-logind[<pid>]: Operation 'suspend' finished.
(The hostname and pid have been redacted in the output above.)
Now here we have our smoking gun
The lid sensor triggered, making the system think I closed the lid and therefore making the system suspend, which is the appropriate response to a closed lid. Only problem is, that I did not close my lid.
Why do you think I closed you? #
Now to figure out why the lid-closure sensor triggered without me closing the darn lid.
How do lid closure sensors work? #
First we need to make a small detour, discussing how lid-closure sensors work. In most laptops, they use a small magnet in the lid above the screen and a hall-effect sensor which can detect changes in a magnetic field.
Experiment time! #
You can live-inspect the close/open
state of your lid-closure sensor on Linux with the following command.
watch -n0.5 cat /proc/acpi/button/lid/LID*/state
To observe changes in this sensor (and not trigger the sleep with it), we need to deactivate the “sleep on lid closure” in the power management settings. Otherwise the system will go to sleep, the second we manage to trigger the sensor. Now with a ThinkPad this still is not enough, as the lid switch is hard-wired to turn off the LCD backlight of the built-in panel. This is something that you can’t disable without completely disabling the lid closure switch.
Therefore this command does not really work for me, but you might want to give it a try :D
Luckily we can check whether we accidentally trigger the switch with something magnetic.
Identifying the culprit #
Now with all the settings in place and the ThinkPad built-in watch
command (if the screen turns black, you have triggered the sensor). We can take a look what triggers the sensor.
I have one of those snazzy new Apple watches that has a MAGNETIC bracelet. See the video below for a demonstration.
So now we have solved the mystery. I wear my watch on my right hand, placing the magnetic watch bracelet on the lid closure sensor from time to time, then triggering the sleep.
How I handle the problem going forward #
Now I could disable the lid closure sensor, or change what happens when you trigger it. But as I did not really trigger the lid-closure sensor that often, I opted to order a new watch band (non-magnetic) and for now just make sure I do not put anything magnetic there.