sd_event_add_defer man page

sd_event_add_defer, sd_event_add_post, sd_event_add_exit — Add static event sources to an event loop


#include <systemd/sd-bus.h>

int sd_event_add_defer(sd_event *event, sd_event_source **source, sd_event_handler_t handler, void *userdata);
int sd_event_add_post(sd_event *event, sd_event_source **source, sd_event_handler_t handler, void *userdata);
int sd_event_add_exit(sd_event *event, sd_event_source **source, sd_event_handler_t handler, void *userdata);
typedef int (*sd_event_handler_t)(sd_event_source *s, void *userdata);


Those three functions add new event sources to an event loop object. The event loop is specified in event, the event source is returned in the source parameter. The event sources are enabled statically and will "fire" when the event loop is run and the conditions described below are met. The handler function will be passed the userdata pointer, which may be chosen freely by the caller.

sd_event_add_defer() adds a new event source that will "fire" the next time the event loop is run. By default, the handler will be called once (SD_EVENT_ONESHOT).

sd_event_add_post() adds a new event source that will "fire" if any event handlers are invoked whenever the event loop is run. By default, the source is enabled permanently (SD_EVENT_ON).

sd_event_add_exit() adds a new event source that will "fire" when the event loop is terminated with sd_event_exit().

The sd_event_source_set_enabled(3) function may be used to enable the event source permanently (SD_EVENT_ON) or to make it fire just once (SD_EVENT_ONESHOT). If the handler function returns a negative error code, it will be disabled after the invocation, even if SD_EVENT_ON mode is set.

Return Value

On success, this functions return 0 or a positive integer. On failure, they return a negative errno-style error code.


Returned errors may indicate the following problems:

Not enough memory to allocate an object.
An invalid argument has been passed.
The event loop is already terminated.
The event loop has been created in a different process.


Functions described here are available as a shared library, which can be compiled and linked to with the libsystemd pkg-config(1) file.

See Also

systemd(1), sd-event(3), sd_event_new(3), sd_event_add_time(3), sd_event_add_signal(3), sd_event_add_child(3), sd_event_source_set_enabled(3)

Referenced By

sd-event(3), sd_event_add_child(3), sd_event_add_io(3), sd_event_add_signal(3), sd_event_add_time(3), sd_event_exit(3), sd_event_new(3), sd_event_run(3), sd_event_set_name(3), sd_event_set_watchdog(3), sd_event_source_get_event(3), sd_event_source_get_pending(3), sd_event_source_set_description(3), sd_event_source_set_enabled(3), sd_event_source_set_prepare(3), sd_event_source_set_priority(3), sd_event_source_set_userdata(3), sd_event_source_unref(3), sd_event_wait(3), systemd.directives(7), systemd.index(7).

Explore man page connections for sd_event_add_defer(3).

sd_event_add_exit(3), sd_event_add_post(3) and sd_event_handler_t(3) are aliases of sd_event_add_defer(3).