1SD_EVENT_EXIT(3)                 sd_event_exit                SD_EVENT_EXIT(3)
2
3
4

NAME

6       sd_event_exit, sd_event_get_exit_code - Ask the event loop to exit
7

SYNOPSIS

9       #include <systemd/sd-event.h>
10
11       int sd_event_exit(sd_event *event, int code);
12
13       int sd_event_get_exit_code(sd_event *event, int *code);
14

DESCRIPTION

16       sd_event_exit() requests the event loop specified in the event event
17       loop object to exit. The code parameter may be any integer value and is
18       returned as-is by sd_event_loop(3) after the last event loop iteration.
19       It may also be queried using sd_event_get_exit_code(), see below.
20
21       When exiting is requested the event loop will stop listening for and
22       dispatching regular event sources. Instead it will proceed with
23       executing only event sources registered with sd_event_add_exit(3) in
24       the order defined by their priority. After all exit event sources have
25       been dispatched the event loop is terminated.
26
27       If sd_event_exit() is invoked a second time while the event loop is
28       still processing exit event sources, the exit code stored in the event
29       loop object is updated, but otherwise no further operation is executed.
30
31       sd_event_get_exit_code() may be used to query the exit code passed into
32       sd_event_exit() earlier.
33
34       While the full positive and negative integer ranges may be used for the
35       exit code, care should be taken not pick exit codes that conflict with
36       regular exit codes returned by sd_event_loop(), if these exit codes
37       shall be distinguishable.
38
39       Note that for most event source types passing the callback pointer as
40       NULL in the respective constructor call (i.e. in sd_event_add_time(3),
41       sd_event_add_signal(3), ...) has the effect of sd_event_exit() being
42       invoked once the event source triggers, with the specified userdata
43       pointer cast to an integer as the exit code parameter. This is useful
44       to automatically terminate an event loop after some condition, such as
45       a time-out or reception of SIGTERM or similar. See the documentation
46       for the respective constructor call for details.
47

RETURN VALUE

49       On success, sd_event_exit() and sd_event_get_exit_code() return 0 or a
50       positive integer. On failure, they return a negative errno-style error
51       code.
52
53   Errors
54       Returned errors may indicate the following problems:
55
56       -EINVAL
57           The event loop object or error code pointer are invalid.
58
59       -ECHILD
60           The event loop was created in a different process.
61
62       -ESTALE
63           The event loop has exited already and all exit handlers are already
64           processed.
65
66       -ENODATA
67           The event loop has not been requested to exit yet.
68

NOTES

70       These APIs are implemented as a shared library, which can be compiled
71       and linked to with the libsystemd pkg-config(1) file.
72

SEE ALSO

74       systemd(1), sd-event(3), sd_event_new(3), sd_event_add_exit(3),
75       sd_event_add_time(3), sd_event_add_signal(3), sd_event_add_io(3),
76       sd_event_add_defer(3), sd_event_add_inotify(3)
77
78
79
80systemd 253                                                   SD_EVENT_EXIT(3)
Impressum