SD_EVENT_...IT_ON_IDLE(3)
π NAME π
okay bestie, so sd_event_set_exit_on_idle, sd_event_get_exit_on_idle β that's the whole vibe here. they turn on (and check on) exit-on-idle support for your event loop. this page lives in the sd_event_set_exit_on_idle part of section 3 of the manual, iykyk. β¨
π¦ SYNOPSIS π¦
#include <systemd/sd-event.h>
int sd_event_set_exit_on_idle(sd_event *event, int b);
int sd_event_get_exit_on_idle(sd_event *event);
like, two lil functions, both returning int, both taking your event pointer. one of them also wants a b. periodt. π
πΈ DESCRIPTION πΈ
sd_event_set_exit_on_idle() is your on/off switch for the exit-on-idle support inside the event loop object you pass in as event. flip it on, and the event loop will exit with a zero exit code when there are no more enabled event sources left. and by "enabled" we mean sources that are SD_EVENT_ON or SD_EVENT_ONESHOT β plus they gotta be non-exit and non-post too. so basically when the party's empty and nobody's waiting on anything, it dips. πͺβ¨
sd_event_get_exit_on_idle() is the vibe check π β it tells you whether exit-on-idle support was previously requested by a call to sd_event_set_exit_on_idle() with a true b parameter, and successfully enabled. both conditions, no cap.
π RETURN VALUE π
slay, so on success: sd_event_set_exit_on_idle() and sd_event_get_exit_on_idle() return a non-zero positive integer if exit-on-idle support was successfully enabled. π
they return zero if exit-on-idle support was explicitly disabled with a false b parameter.
and on failure? negative errno-style error code, as per usual. π
π Errors
here's what those returned errors can mean:
-ECHILDβ the event loop was created in a different process, library or module instance. it's not yours, bestie, you can't touch it. π-EINVALβ the event loop object you passed was invalid. rip.
β NOTES β
the functions described here are available as a shared library, which you can compile against and link to with the libsystemd pkg-config(1) file. π₯
all functions listed here are thread-agnostic, and only a single thread may operate on a given object at any given time. different threads can access the same object at different times though. and multiple independent objects can be used from different threads in parallel. so like, share the toy but not at the exact same second, okay? π«Ά
β οΈ real talk: the code described here usesgetenv(3), which is declared to be not multi-thread-safe. that means if you're calling the functions described here, you must not callsetenv(3)from a parallel thread. the recommendation is to only do calls tosetenv()from an early phase of the program, when no other threads have been started. no exceptions, this one's important. π
π HISTORY π
sd_event_set_exit_on_idle() and sd_event_get_exit_on_idle() were added in version 259. they're new new. β¨
π SEE ALSO π
systemd(1), sd-event(3), sd_event_new(3), sd_event_add_io(3), sd_event_add_time(3), sd_event_add_signal(3), sd_event_add_child(3), sd_event_add_inotify(3), sd_event_add_defer(3), systemd.service(5)
go read those too, they're all part of the same friend group. π
and that's the whole page, bestie!! π this lil masterpiece is from systemd 262.1 and it's the SD_EVENT_...IT_ON_IDLE(3) page. thanks for coming to my ted talk, mwah πβ¨π¦
π¦ where this page comes from
- arch rolling: systemd-libs 262.1-1 Β· LGPL-2.1-or-later AND CC0-1.0 AND GPL-2.0-or-later WITH Linux-syscall-note
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms