1SD_EVENT_ADD_DEFER(3)         sd_event_add_defer         SD_EVENT_ADD_DEFER(3)
2
3
4

NAME

6       sd_event_add_defer, sd_event_add_post, sd_event_add_exit,
7       sd_event_handler_t - Add static event sources to an event loop
8

SYNOPSIS

10       #include <systemd/sd-event.h>
11
12       typedef struct sd_event_source sd_event_source;
13
14       typedef int (*sd_event_handler_t)(sd_event_source *s, void *userdata);
15
16       int sd_event_add_defer(sd_event *event, sd_event_source **source,
17                              sd_event_handler_t handler, void *userdata);
18
19       int sd_event_add_post(sd_event *event, sd_event_source **source,
20                             sd_event_handler_t handler, void *userdata);
21
22       int sd_event_add_exit(sd_event *event, sd_event_source **source,
23                             sd_event_handler_t handler, void *userdata);
24

DESCRIPTION

26       These three functions add new static event sources to an event loop.
27       The event loop object is specified in the event parameter, the event
28       source object is returned in the source parameter. The event sources
29       are enabled statically and will "fire" when the event loop is run and
30       the conditions described below are met.
31
32       The handler is a function to call or NULL. The handler function will be
33       passed the userdata pointer, which may be chosen freely by the caller.
34       The handler may return negative to signal an error (see below), other
35       return values are ignored. If handler is NULL, a default handler that
36       calls sd_event_exit(3) will be used.
37
38       sd_event_add_defer() adds a new event source that will be dispatched
39       instantly, before the event loop goes to sleep again and waits for new
40       events. By default, the handler will be called once (SD_EVENT_ONESHOT).
41       Note that if the event source is set to SD_EVENT_ON the event loop will
42       never go to sleep again, but continuously call the handler, possibly
43       interleaved with other event sources.
44
45       sd_event_add_post() adds a new event source that is run before the
46       event loop will sleep and wait for new events, but only after at least
47       one other non-post event source was dispatched. By default, the source
48       is enabled permanently (SD_EVENT_ON). Note that this event source type
49       will still allow the event loop to go to sleep again, even if set to
50       SD_EVENT_ON, as long as no other event source is ever triggered.
51
52       sd_event_add_exit() adds a new event source that will be dispatched
53       when the event loop is terminated with sd_event_exit(3).
54
55       The sd_event_source_set_enabled(3) function may be used to enable the
56       event source permanently (SD_EVENT_ON) or to make it fire just once
57       (SD_EVENT_ONESHOT).
58
59       If the handler function returns a negative error code, it will either
60       be disabled after the invocation, even if the SD_EVENT_ON mode was
61       requested before, or it will cause the loop to terminate, see
62       sd_event_source_set_exit_on_failure(3).
63
64       To destroy an event source object use sd_event_source_unref(3), but
65       note that the event source is only removed from the event loop when all
66       references to the event source are dropped. To make sure an event
67       source does not fire anymore, even when there's still a reference to it
68       kept, consider setting the event source to SD_EVENT_OFF with
69       sd_event_source_set_enabled(3).
70
71       If the second parameter of these functions is passed as NULL no
72       reference to the event source object is returned. In this case the
73       event source is considered "floating", and will be destroyed implicitly
74       when the event loop itself is destroyed.
75
76       If the handler parameter to sd_event_add_defer() or sd_event_add_post()
77       is NULL, and the event source fires, this will be considered a request
78       to exit the event loop. In this case, the userdata parameter, cast to
79       an integer, is passed as the exit code parameter to sd_event_exit(3).
80       Similar functionality is not available for sd_event_add_exit(), as
81       these types of event sources are only dispatched when exiting anyway.
82

RETURN VALUE

84       On success, these functions return 0 or a positive integer. On failure,
85       they return a negative errno-style error code.
86
87   Errors
88       Returned errors may indicate the following problems:
89
90       -ENOMEM
91           Not enough memory to allocate an object.
92
93       -EINVAL
94           An invalid argument has been passed.
95
96       -ESTALE
97           The event loop is already terminated.
98
99       -ECHILD
100           The event loop has been created in a different process, library or
101           module instance.
102

NOTES

104       Functions described here are available as a shared library, which can
105       be compiled against and linked to with the libsystemd pkg-config(1)
106       file.
107
108       The code described here uses getenv(3), which is declared to be not
109       multi-thread-safe. This means that the code calling the functions
110       described here must not call setenv(3) from a parallel thread. It is
111       recommended to only do calls to setenv() from an early phase of the
112       program when no other threads have been started.
113

SEE ALSO

115       systemd(1), sd-event(3), sd_event_new(3), sd_event_now(3),
116       sd_event_add_io(3), sd_event_add_time(3), sd_event_add_signal(3),
117       sd_event_add_child(3), sd_event_add_inotify(3),
118       sd_event_source_set_enabled(3), sd_event_source_set_priority(3),
119       sd_event_source_set_userdata(3), sd_event_source_set_description(3),
120       sd_event_source_set_floating(3), sd_event_exit(3)
121
122
123
124systemd 254                                              SD_EVENT_ADD_DEFER(3)
Impressum