[systemd-devel] "systemd-inhibit" in service files?

Colin Guthrie gmane at colin.guthr.ie
Sun Nov 11 02:51:00 PST 2012


'Twas brillig, and Lennart Poettering at 10/11/12 00:06 did gyre and gimble:
> On Tue, 06.11.12 22:16, Manuel Reimer (Manuel.Spam at nurfuerspam.de) wrote:
> 
>> Hello,
>>
>> if I want a daemon to, for example listen for the power button, then
>> there are two possible solutions. Either configure systemd to not
>> longer handle the power button or register an "inhibitor" to make
>> systemd stop handling the power button.
>>
>> Is it good practice to use "systemd-inhibit" in service files to use
>> the "inhibitor" way to "free" the power button or is the preferred
>> way to fix the daemon to inhibit on its own?
> 
> If I were you I'd always do that in the service code itself rather than
> wrap it in a "system-inhibit" invocation. In fact, calling the bus call
> for this is dead simple. Just one bus call, and that's it.
> 
> http://www.freedesktop.org/wiki/Software/systemd/inhibit
> 
> Yeah, that doc is long, inhibition is a surprisingly complex
> topic... That said the actuall code bits you need are tiny. For your
> usecase, just do this somewhere at the top of your service (in D-Bus
> pseudo code):
> 
> fd = Inhibit("handle-power-key", "Power Key Handler", "I am handling the power key now!", "block");
> 
> And then you can just leak the fd this returns, if you want to handle
> the key during the entire runtime of your service, since the kernel will
> close the fd anyway if the process dies. 

Should your app use exec(), I guess you have to be somewhat careful
about CLOEXEC in this context tho'?

Col


-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited http://www.tribalogic.net/
Open Source:
  Mageia Contributor http://www.mageia.org/
  PulseAudio Hacker http://www.pulseaudio.org/
  Trac Hacker http://trac.edgewall.org/



More information about the systemd-devel mailing list