SD_EVENT...SCRIPTION(3)
π sd_event_source_set_description(3) β giving your event sources cute lil names π
Okay bestie, so this page lives in manual section 3, it's called sd_event_source_set_description, and it's literally all about naming your event sources so debugging doesn't make you cry π. Two functions, one goal: labels. Let's go π«Ά
πΈ NAME
sd_event_source_set_description, sd_event_source_get_description β set or retrieve descriptive names of event sources β¨
π SYNOPSIS
#include <systemd/sd-event.h>
int sd_event_source_set_description(sd_event_source *source,
const char *description);
int sd_event_source_get_description(sd_event_source *source,
const char **ret);
π¦ DESCRIPTION
So sd_event_source_set_description() is the one that lets you slap an arbitrary descriptive name on the event source object you passed in as source π. Like, give it a name, it deserves one. That name then shows up in debugging messages that sd-event(3) generates for this event source, and you can pull it back out later with sd_event_source_get_description() when you're in debugging mode and need to know which source is which π. The description parameter has to point at a NUL-terminated string, or be NULL. If you pass NULL, the descriptive name just gets unset β poof, gone π¨. The string gets copied internally, so after the function returns, the description argument is not referenced anymore. No dangling vibes β¨.
Then sd_event_source_get_description() is the getter, the retrieval girlie πββοΈ β it queries the current descriptive name assigned to the event source object source and hands you back a pointer to that current name in ret, stored in memory internal to the event source. Important though, bestie: that memory is invalidated when the event source is destroyed or the descriptive name is changed β οΈ. So don't go hoarding that pointer, it's not yours forever, no cap.
And here's a fun fact π: event source objects generally have no description set when they're created β like a fresh account with no bio π β except for UNIX signal event sources created with sd_event_add_signal(3), whose descriptive name is initialized to the signal's C constant name (e.g. "SIGINT" or "SIGTERM"). Those ones came pre-named, main character energy π.
π₯ RETURN VALUE
On success, both sd_event_source_set_description() and sd_event_source_get_description() return a non-negative integer π. On failure, they return a negative errno-style error code π.
π Errors
The errors you might get back mean these things, iykyk:
-EINVALβsourceis not a valid pointer to ansd_event_sourceobject, or thedescriptionargument forsd_event_source_get_description()isNULL. Basically you handed it nonsense π.-ENOMEMβ not enough memory to copy the name π.-ECHILDβ the event loop has been created in a different process, library or module instance. Wrong building, wrong floor π’.-ENXIOβ no name was set for the event source. Nothing to get, bestie, the bio is empty π.
π 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 may access the same object at different times. And multiple independent objects may be used from different threads in parallel β parallel slay, but one thread per object at a time, periodt π .
β οΈ Also listen up: the code described here usesgetenv(3), which is declared to be not multi-thread-safe. That means the code calling the functions described here must not callsetenv(3)from a parallel thread π¬. It's recommended to only do calls tosetenv()from an early phase of the program when no other threads have been started. Do your env stuff first, then start the threads, fr fr π§.
β HISTORY
sd_event_source_set_description() and sd_event_source_get_description() were added in version 229 π. Old but iconic, honestly.
π SEE ALSO
sd-event(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), sd_event_source_set_userdata(3) β go read the whole friend group πΈ
π That's the whole page, bestie! Straight from systemd 261.3, dated and everything, on the SD_EVENT...SCRIPTION(3) page. Go name your event sources and live your truth πβ¨ππ¦
π¦ where this page comes from
- ubuntu stonking: libsystemd-dev 261.3-0ubuntu3 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms