SD_EVENT_...ET_ENABLED(3)
π NAME π
okay bestie, welcome to the sd_event_source_set_enabled(3) page from the systemd manual β the header abbreviates it as SD_EVENT_...ET_ENABLED(3), and today we're talking about sd_event_source_set_enabled, sd_event_source_get_enabled, SD_EVENT_ON, SD_EVENT_OFF, and SD_EVENT_ONESHOT β the whole enable-or-disable situation for event sources. Periodt π
β¨ SYNOPSIS β¨
here's the exact shape of it, no cap:
#include <systemd/sd-event.h>
enum {
SD_EVENT_OFF = 0,
SD_EVENT_ON = 1,
SD_EVENT_ONESHOT = -1,
};
int sd_event_source_set_enabled(sd_event_source *source, int enabled);
int sd_event_source_get_enabled(sd_event_source *source, int *ret);
π¦ DESCRIPTION π¦
okay so sd_event_source_set_enabled() is your enable/disable switch for the event source object you pass as source. The enabled parameter takes one of these three values:
SD_EVENT_ONβ turn the event source on.SD_EVENT_OFFβ turn it off.SD_EVENT_ONESHOTβ turn it on, but the event source will be automatically reset toSD_EVENT_OFFafter one dispatch. One dispatch and it's out, iconic behavior honestly.
small but important detail: if you invoke this with SD_EVENT_OFF, the event source source may be NULL, and in that case the function does nothing. Otherwise, source must be a valid pointer to an sd_event_source object. no fake pointers, bestie π«Ά
event sources that are disabled will not result in event loop wakeups and will not be dispatched, until they are enabled again. so yeah β disabled means quiet, no wakeups, no dispatch, until you switch it back on β¨
sd_event_source_get_enabled() is the query girlie. it checks whether the event source object source is currently enabled or not. If both the source and the output parameter ret are NULL, this function returns false. Otherwise, source must be a valid pointer to an sd_event_source object.
If the output parameter ret is not NULL, it is set to the enablement state β one of SD_EVENT_ON, SD_EVENT_OFF, or SD_EVENT_ONESHOT. The function also returns true if the event source is not disabled. yes, that's the vibe check π
event source objects are enabled when they are first created with calls such as sd_event_add_io(3) and sd_event_add_time(3). However, depending on the event source type, they are enabled continuously (SD_EVENT_ON) or only for a single invocation of the event source handler (SD_EVENT_ONESHOT). For details, see the respective manual pages β iykyk π
and real talk: because event source objects stay active and may be dispatched as long as there is at least one reference to them, in many cases it is a good idea to combine a call to sd_event_source_unref(3) with a prior call to sd_event_source_set_enabled() with SD_EVENT_OFF, to ensure the event source is not dispatched again until all other remaining references are dropped. clean up your references, bestie π§Ήπ
π«Ά RETURN VALUE π«Ά
On success, sd_event_source_set_enabled() returns a non-negative integer.
sd_event_source_get_enabled() returns zero if the source is disabled (SD_EVENT_OFF) and a positive integer otherwise.
On failure, they return a negative errno-style error code. rude but informative π
π Errors π
Returned errors may indicate the following problems:
-EINVALβsourceis not a valid pointer to ansd_event_sourceobject.-ENOMEMβ Not enough memory.-ECHILDβ The event loop has been created in a different process, library or module instance.
π NOTES π
Functions described here are available as a shared library, which can be compiled against and linked 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. Multiple independent objects may be used from different threads in parallel. so: one thread on one object at a time, but the timeline can still be cute π¦
π¨ caveat time, bestie: the code described here usesgetenv(3), which is declared to be not multi-thread-safe. This means that the code calling the functions described here must not callsetenv(3)from a parallel thread. It is recommended to only do calls tosetenv()from an early phase of the program when no other threads have been started. do your env stuff early and avoid the chaos π
β HISTORY β
sd_event_source_set_enabled() and sd_event_source_get_enabled() were added in version 229. vintage-ish but still serving π
π SEE ALSO π
go read these next, bestie:
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_unref(3)sd_event_source_set_ratelimit(3)
that's the whole page, bestie π footer check: source/version systemd 261.3, page tag SD_EVENT_...ET_ENABLED(3) β no date printed in this little footer, so that's our cute version-and-tag sign-off. mwah πβ¨
π¦ 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