[systemd-devel] [PATCH 1/2] Add sd_event_loop_timeout to sd_event

Lennart Poettering lennart at poettering.net
Wed Feb 4 09:20:55 PST 2015


On Wed, 04.02.15 17:40, Didier Roche (didrocks at ubuntu.com) wrote:

> Le 04/02/2015 17:10, Lennart Poettering a écrit :
> >On Wed, 04.02.15 17:05, Didier Roche (didrocks at ubuntu.com) wrote:
> >
> >>Hey,
> >>
> >>I rewrote a version of this patch including the feedback on the list. As per
> >>IRC discussion, (and after giving up the busy loop for a rewrite with
> >>epool), I did rebase it again on sd_event.
> >>
> >>I'm only proposing there up for review the 2 first patches (without plymouth
> >>communication, cancel support, i18n, man pages and the service and socket)
> >>so that I don't have to rebase all other 10 patches on a moving
> >>ground.
> >Tom just added support for installing timer events with a NULL
> >callback, that trigger event loop exit. I kinda prefer that solution
> >over a new call sd_event_loop() with timeout.
> >
> >      sd_event_add_time(event, NULL, CLOCK_MONOTONIC, now(CLOCK_MONOTONIC) + 5 * USEC_PER_SEC, NULL, NULL);
> 
> So, it means that I need to reset it after any received activity, is that
> ok? (as this will be really frequent as each clients in parallel can send a
> message each 50ms). The goal is to have a global "inactivity" timeout.
> 
> I didn't see a way to cancel this event source though?

Oh, I see, you actually want a real idle logic, not just a normal
timer.

So far, for daemons like timedated, localed and so on, we are using an
idle logic that is implemented in bus_event_loop_with_idle() in
src/libsystemd/sd-bus/bus-util.c. It does considerably more than what
you need (since it contains all the magic to racefully do exit-on-idle
for bus services so that no bus messages are lost). 

I think the best would be to take inspiration from that code, isolate
there basic minimum out of it, without all the dbus logic, and then
stick that in your C file.

We can generalize such exit-on-idle logic one day, somewhere between
sd-bus and sd-event, but that requires considerabe design work, so
that we find a generic solution that works for you and also covers
this dbus case without hacks. For now it's hence better if you just
take inspiration from bus_event_loop_with_idle(), drop all the
bus-specific bits, and stick it in your .c code...

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list