1SD_EVENT_ADD_DEFER(3) sd_event_add_defer SD_EVENT_ADD_DEFER(3)
2
3
4
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
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
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. The handler function will be
31 passed the userdata pointer, which may be chosen freely by the caller.
32
33 sd_event_add_defer() adds a new event source that will be dispatched
34 instantly, before the event loop goes to sleep again and waits for new
35 events. By default, the handler will be called once (SD_EVENT_ONESHOT).
36 Note that if the event source is set to SD_EVENT_ON the event loop will
37 never go to sleep again, but continuously call the handler, possibly
38 interleaved with other event sources.
39
40 sd_event_add_post() adds a new event source that is run before the
41 event loop will sleep and wait for new events, but only after at least
42 one other non-post event source was dispatched. By default, the source
43 is enabled permanently (SD_EVENT_ON). Note that this event source type
44 will still allow the event loop to go to sleep again, even if set to
45 SD_EVENT_ON, as long as no other event source is ever triggered.
46
47 sd_event_add_exit() adds a new event source that will be dispatched
48 when the event loop is terminated with sd_event_exit(3).
49
50 The sd_event_source_set_enabled(3) function may be used to enable the
51 event source permanently (SD_EVENT_ON) or to make it fire just once
52 (SD_EVENT_ONESHOT).
53
54 If the handler function returns a negative error code, it will be
55 disabled after the invocation, even if the SD_EVENT_ON mode was
56 requested before.
57
58 To destroy an event source object use sd_event_source_unref(3), but
59 note that the event source is only removed from the event loop when all
60 references to the event source are dropped. To make sure an event
61 source does not fire anymore, even when there's still a reference to it
62 kept, consider setting the event source to SD_EVENT_OFF with
63 sd_event_source_set_enabled(3).
64
65 If the second parameter of these functions is passed as NULL no
66 reference to the event source object is returned. In this case the
67 event source is considered "floating", and will be destroyed implicitly
68 when the event loop itself is destroyed.
69
70 If the handler parameter to sd_event_add_defer() or sd_event_add_post()
71 is NULL, and the event source fires, this will be considered a request
72 to exit the event loop. In this case, the userdata parameter, cast to
73 an integer, is passed as the exit code parameter to sd_event_exit(3).
74 Similar functionality is not available for sd_event_add_exit(), as
75 these types of event sources are only dispatched when exiting anyway.
76
78 On success, these functions return 0 or a positive integer. On failure,
79 they return a negative errno-style error code.
80
81 Errors
82 Returned errors may indicate the following problems:
83
84 -ENOMEM
85 Not enough memory to allocate an object.
86
87 -EINVAL
88 An invalid argument has been passed.
89
90 -ESTALE
91 The event loop is already terminated.
92
93 -ECHILD
94 The event loop has been created in a different process.
95
97 These APIs are implemented as a shared library, which can be compiled
98 and linked to with the libsystemd pkg-config(1) file.
99
101 systemd(1), sd-event(3), sd_event_new(3), sd_event_now(3),
102 sd_event_add_io(3), sd_event_add_time(3), sd_event_add_signal(3),
103 sd_event_add_child(3), sd_event_add_inotify(3),
104 sd_event_source_set_enabled(3), sd_event_source_set_priority(3),
105 sd_event_source_set_userdata(3), sd_event_source_set_description(3),
106 sd_event_source_set_floating(3), sd_event_exit(3)
107
108
109
110systemd 249 SD_EVENT_ADD_DEFER(3)