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

Lennart Poettering lennart at poettering.net
Wed Nov 14 16:26:55 PST 2012


On Sun, 11.11.12 10:51, Colin Guthrie (gmane at colin.guthr.ie) wrote:

> > 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'?

The C D-Bus bindings set O_CLOEXEC anyway, and so do the the GIO
bindings AFAIK.

Lennart

-- 
Lennart Poettering - Red Hat, Inc.


More information about the systemd-devel mailing list