Bug 904827 - systemd-inhibit doesn't work when called from pm-utils scripts (using Gnome)
Summary: systemd-inhibit doesn't work when called from pm-utils scripts (using Gnome)
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: systemd
Version: 18
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: systemd-maint
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2013-01-27 19:08 UTC by Hedayat Vatankhah
Modified: 2013-04-09 11:20 UTC (History)
8 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2013-04-09 11:20:38 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Hedayat Vatankhah 2013-01-27 19:08:33 UTC
Description of problem:
Since Gnome no longer provides the possibility of inhibiting suspension when laptop's lid is closed (on AC power), I tried to do it myself. I want the system to suspend when on battery, but not suspend when on AC. Therefore, I added the following script in /etc/pm/power.d/01_lidclose.sh, so that it runs a systemd-inhibit command when using AC, and kills it when on battery. If I run the script manually, it works as expected and prevents suspends when the lid is closed. However, if I unplug AC and plug it again, the script is run by system (apparently, upower.service). also, systemd-inhibit shows that this inhibitor is running. So, it seems that everything is OK. However, if I close the lid, the laptop suspends.
-------------------------
The script (/etc/pm/power.d/01_lidclose.sh):

#!/bin/bash

if on_ac_power; then
	systemd-inhibit --what=handle-lid-switch --who="AC Lid-Close-Suspend Inhibitor" --why="Since AC power is available" --mode=block sleep 1000d > /dev/null &
	echo $! > /run/lid_close.pid
else
	kill -9 $(cat /run/lid_close.pid)
fi

exit 0

-------------------------
Output of 'journalctl -u systemd-logind.service -f' when the script is run manually:
ژانویه 27 22:24:11 hedayat-lap.hedayat-net systemd-logind[4992]: Lid closed.
ژانویه 27 22:24:17 hedayat-lap.hedayat-net systemd-logind[4992]: Lid opened.

When run automatically after unplugging and re-pluging AC:
ژانویه 27 22:24:34 hedayat-lap.hedayat-net systemd-logind[4992]: Lid closed.
ژانویه 27 22:24:34 hedayat-lap.hedayat-net systemd-logind[4992]: Suspending...
ژانویه 27 22:24:55 hedayat-lap.hedayat-net systemd-logind[4992]: Lid opened.

------------------------
'systemd-inhibit --list' output when run in both cases:
[hedayat@hedayat-lap ~]% systemd-inhibit --list
WHAT                  WHO                  WHY                  MODE     UID    PID
handle-power-key:handle-suspend-key:handle-hibernate-key hedayat              GNOME handlin...sses block   1000   1347
sleep                 hedayat              GNOME needs t...reen delay   1000   1347
handle-lid-switch     AC Lid-Close-...itor Since AC powe...able block      0  22461

3 inhibitors listed.
-------------------------


Version-Release number of selected component (if applicable):
systemd-197-1.fc18.1.x86_64

How reproducible:
100%

Steps to Reproduce:
1. Put the above script in /etc/pm/power.d/
2. Make sure laptop is running on battery
3. Connect AC
4. Verify that the inhibitor is listed in 'systemd-inhibit --list' output
5. Close the lid
  
Actual results:
Laptop suspends

Expected results:
Should no suspend

Additional info:
If you run the script manually while laptop is on AC instead of steps 2 and 3, laptop doesn't suspend.

Comment 1 Lukáš Nykrýn 2013-01-28 12:25:36 UTC
Other way how to set this directly in gnome is
gsettings set org.gnome.settings-daemon.plugins.power lid-close-ac-action  blank

Comment 2 Hedayat Vatankhah 2013-01-28 13:17:39 UTC
It doesn't work too! If I close the lid, laptop suspends. This is my status after running the command:

[hedayat@hedayat-lap ~]% gsettings get org.gnome.settings-daemon.plugins.power lid-close-battery-action 
'suspend'
[hedayat@hedayat-lap ~]% gsettings get org.gnome.settings-daemon.plugins.power lid-close-ac-action 
'blank'

Comment 3 Lennart Poettering 2013-03-07 14:40:40 UTC
/etc/pm/power.d/ is not supported by logind's own suspend handling. Also, any hook directory like it is way too late to still inhibit the suspend.

Please file a bug against GNOME if the gsettings trick doesn't work.

Comment 4 Hedayat Vatankhah 2013-03-18 09:42:27 UTC
Why /etc/pm/power.d/ should be supported by logind?! It is supported by upower, and it does run the scripts. (Notice that the hook is NOT intended to be run when you want to suspend, or wake up from suspend. The hook is run when the AC cable is plugged or unplugged. And it does run my systemd-inhibit command. So, the problem is this: systemd-inhibit is being run, and systemd-inhibit --list shows that an inhibitor is running, but it doesn't inhibit suspension. 
Is it important who has run systemd-inhibit? Consider I write my own custom application to run systemd-inhibit when AC cable is plugged. Should it work or not? I guess it should work. So, why upower should not be able to inhibit suspension by running systemd-inhibit? Looks weird!

Comment 5 Lennart Poettering 2013-04-09 11:20:38 UTC
Note that the lid switch ignores any inhibtors by default, i.e. LidSwitchIgnoreInhibited=yes is the default. See logind.conf(5).

If the GNOME settings for controlling what happens if you close the lid don't work, then please file a bug against GNOME.


Note You need to log in before you can comment on or make changes to this bug.