How do remove a systemd-inhibit block

gnomesuspendsystemd

The documentation about Systemd's Inhibitor Locks and also man systemd-inhibit go to great length to explain how to start a process in a way as it blocks something (e.g. the handle-lid-switch event).

I was unable to find a way to allow me to remove such a "lock"/"inhibit"/"block".

Question: Is there a way to remove the systemd-inhibit lock, for instance via a dbus message?

Background: what would I need to remove a inhibitor lock for**

My Laptop has a laptop-lid close switch, which systemd-logind monitors and in case the lid is closed suspends the laptop – functionality "close-lid -> suspend".

Once the laptop is placed in its docking station, to make user of a bigger screen, Gnome's gsd-power arbitrarily ( and erroneously and without any available setting in Gnome to change it ) decides to create a inhibitor lock, preventing the functionality "close-lid -> suspend" to work.

Knowing how to remove an inhibitor lock, would allow me to remedy the erronous setting done by Gnome's gnome-setting-deamon power gsd-power. Gnome's setting is wrong, because manually invoking suspend systemctl suspend showed indeed no problem.

The inhibitor lock I would like to remove, as listed in systemd-inhibit --list is this:

     Who: alex (UID 1000/alex, PID 4248/gsd-power)
    What: handle-lid-switch
     Why: Multiple displays attached
    Mode: block

Best Answer

From the developer documentation of the inhibitor locks:

Inhibit() returns a single value, a file descriptor that encapsulates the lock. As soon as the file descriptor is closed (and all its duplicates) the lock is automatically released. If the client dies while the lock is taken the kernel automatically closes the file descriptor so that the lock is automatically released. A delay lock taken this way should be released ASAP on reception of PrepareForShutdown(true) (see below), but of course only after execution of the actions the application wanted to delay the operation for in the first place.

You probably don't want to kill gsd-power, so you would need to close the file descriptor that encapsulates the lock. It is most likely held by gsd-power. Forcing another process to close one of its file descriptors is not a normal thing to do, and might cause some side effects within gsd-power. But if you want to do it, read this question in Stack Overflow.

Instead, you might try removing gsd-power's permission to execute the DBus action org.freedesktop.login1.inhibit-handle-lid-switch. The man page dbus-daemon(1) might be helpful.

Related Question