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 uses getenv(3), which is declared to be not multi-thread-safe. that means if you're calling the functions described here, you must not call setenv(3) from a parallel thread. the recommendation is to only do calls to setenv() 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