SD_EVENT_..._GET_EVENT(3)

πŸ’… SD_EVENT_..._GET_EVENT(3) β€” the sd_event_source_get_event page, bestie edition

ok so real quick, before we get into it: this whole page lives inside sd_event_source_get_event world, and the manual is literally called SD_EVENT_..._GET_EVENT(3). that's the vibe. let's go 🫢


✨ NAME ✨

sd_event_source_get_event β€” bestie, this is the one that gets you the event loop that your event source is attached to πŸŽ€


✨ SYNOPSIS ✨

#include <systemd/sd-event.h>

sd_event* sd_event_source_get_event(sd_event_source *source);

that's it. that's the whole function. icon behavior tbh πŸ‘‘


✨ DESCRIPTION ✨

okay so sd_event_source_get_event() is what you call when you have an event source and you're like "wait. which event loop are you even hanging out with?" πŸ’­

you pass in that event source as source, and it hands you back the event loop object that source is associated with. simple. elegant. slay ✨

and where did that event loop come from? not from nowhere, bes β€” the event loop object gets specified back when the event source object was created, via calls like sd_event_add_io(3) or sd_event_add_time(3). so it's giving "you already met your own event loop, you just forgot" πŸ˜­πŸ’–


✨ RETURN VALUE ✨

  • on success β€” sd_event_source_get_event() returns the associated event loop object πŸ’–
  • on failure β€” it returns NULL πŸ’€

that's the whole deal. NULL means something went sideways, periodt.


✨ NOTES ✨

okay the notes section, everybody sit down, this is the important lore 🧚

  • everything described here is available as a shared library β€” you can compile against it and link to it with the libsystemd pkg-config(1) file. yes, that's the pkg-config. go off πŸ”₯
  • all the functions listed here are thread-agnostic β€” but heads up, 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, no cap. and multiple independent objects? those can be used from different threads in parallel, all day, go off 🌈
  • 🚨 okay this one matters: the code described here uses getenv(3), which is declared to be not multi-thread-safe. which means: if you're calling the functions described here, you must not call setenv(3) from a parallel thread. nope. don't. πŸ™ˆ
the recommended move: only do calls to setenv() from an early phase of the program, back when no other threads have been started yet. like, before the party gets going. πŸŽ€

✨ HISTORY ✨

sd_event_source_get_event() was added in version 229. so it's been iconic for a minute πŸ’…


✨ SEE ALSO ✨

go read these next, bestie, they're all part of the same friend group πŸ¦‹


🌸 mwah, that's the page. this one's from systemd 261.3 and it's called SD_EVENT_..._GET_EVENT(3) β€” now go get yourself an event loop, you deserve it πŸ’œ
πŸ“¦ where this page comes from