Skip systemd inhibitor when switching the power status

Systemd inhibitor blocks the power switching operations when needed. However, it also blocks the CriticalPowerAction when upower tries to hibernate or poweroff the system.

To skip is, put the following Polkit rules in /usr/share/polit-1/rules.d for your app.

1
2
3
4
5
6
7
8
9
10
polkit.addRule(function(action, subject) {
if ((action.id == "org.freedesktop.login1.power-off-ignore-inhibit" ||
action.id == "org.freedesktop.login1.reboot-ignore-inhibit" ||
action.id == "org.freedesktop.login1.halt-ignore-inhibit" ||
action.id == "org.freedesktop.login1.suspend-ignore-inhibit" ||
action.id == "org.freedesktop.login1.hibernate-ignore-inhibit") &&
subject.user == "root") {
return polkit.Result.YES;
}
});