Debian Codegraph @

upstream/debian-unstable/man3/sd_event_exit.3

raw
1 '\" t
2 .TH "SD_EVENT_EXIT" "3" "" "systemd 261~rc3" "sd_event_exit"
3 .\" -----------------------------------------------------------------
4 .\" * Define some portability stuff
5 .\" -----------------------------------------------------------------
6 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 .\" http://bugs.debian.org/507673
8 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
9 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 .ie \n(.g .ds Aq \(aq
11 .el .ds Aq '
12 .\" -----------------------------------------------------------------
13 .\" * set default formatting
14 .\" -----------------------------------------------------------------
15 .\" disable hyphenation
16 .nh
17 .\" disable justification (adjust text to left margin only)
18 .ad l
19 .\" -----------------------------------------------------------------
20 .\" * MAIN CONTENT STARTS HERE *
21 .\" -----------------------------------------------------------------
22 .SH "NAME"
23 sd_event_exit, sd_event_get_exit_code \- Ask the event loop to exit
24 .SH "SYNOPSIS"
25 .sp
26 .ft B
27 .nf
28 #include <systemd/sd\-event\&.h>
29 .fi
30 .ft
31 .HP \w'int\ sd_event_exit('u
32 .BI "int sd_event_exit(sd_event\ *" "event" ", int\ " "code" ");"
33 .HP \w'int\ sd_event_get_exit_code('u
34 .BI "int sd_event_get_exit_code(sd_event\ *" "event" ", int\ *" "ret" ");"
35 .SH "DESCRIPTION"
36 .PP
37 \fBsd_event_exit()\fR
38 requests the event loop specified in the
39 \fIevent\fR
40 event loop object to exit\&. The
41 \fIcode\fR
42 parameter may be any integer value and is returned as\-is by
43 \fBsd_event_loop\fR(3)
44 after the last event loop iteration\&. It may also be queried using
45 \fBsd_event_get_exit_code()\fR, see below\&.
46 .PP
47 When exiting is requested the event loop will stop listening for and dispatching regular event sources\&. Instead it will proceed with executing only event sources registered with
48 \fBsd_event_add_exit\fR(3)
49 in the order defined by their priority\&. After all exit event sources have been dispatched the event loop is terminated\&.
50 .PP
51 If
52 \fBsd_event_exit()\fR
53 is invoked a second time while the event loop is still processing exit event sources, the exit code stored in the event loop object is updated, but otherwise no further operation is executed\&.
54 .PP
55 \fBsd_event_get_exit_code()\fR
56 may be used to query the exit code passed to an earlier call of
57 \fBsd_event_exit()\fR\&. The return parameter
58 \fIret\fR
59 may be set to
60 \fBNULL\fR, in order to simply check if
61 \fBsd_event_exit()\fR
62 has been called before (as
63 \fBsd_event_get_exit_code()\fR
64 fails with
65 \fB\-ENODATA\fR
66 if that\*(Aqs not the case, see below)\&.
67 .PP
68 While the full positive and negative integer ranges may be used for the exit code, care should be taken not pick exit codes that conflict with regular exit codes returned by
69 \fBsd_event_loop()\fR, if these exit codes shall be distinguishable\&.
70 .PP
71 Note that for most event source types passing the callback pointer as
72 \fBNULL\fR
73 in the respective constructor call (i\&.e\&. in
74 \fBsd_event_add_time\fR(3),
75 \fBsd_event_add_signal\fR(3), \&...) has the effect of
76 \fBsd_event_exit()\fR
77 being invoked once the event source triggers, with the specified userdata pointer cast to an integer as the exit code parameter\&. This is useful to automatically terminate an event loop after some condition, such as a timeout or reception of
78 \fBSIGTERM\fR
79 or similar\&. See the documentation for the respective constructor call for details\&.
80 .SH "RETURN VALUE"
81 .PP
82 On success,
83 \fBsd_event_exit()\fR
84 and
85 \fBsd_event_get_exit_code()\fR
86 return 0 or a positive integer\&. On failure, they return a negative errno\-style error code\&.
87 .SS "Errors"
88 .PP
89 Returned errors may indicate the following problems:
90 .PP
91 \fB\-EINVAL\fR
92 .RS 4
93 The event loop object or error code pointer are invalid\&.
94 .RE
95 .PP
96 \fB\-ECHILD\fR
97 .RS 4
98 The event loop was created in a different process, library or module instance\&.
99 .RE
100 .PP
101 \fB\-ESTALE\fR
102 .RS 4
103 The event loop has exited already and all exit handlers are already processed\&.
104 .RE
105 .PP
106 \fB\-ENODATA\fR
107 .RS 4
108 Returned by
109 \fBsd_event_get_exit_code()\fR
110 in case the event loop has not been requested to exit yet\&.
111 .RE
112 .SH "NOTES"
113 .PP
114 Functions described here are available as a shared library, which can be compiled against and linked to with the
115 \fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
116 file\&.
117 .PP
118 The code described here uses
119 \fBgetenv\fR(3), which is declared to be not multi\-thread\-safe\&. This means that the code calling the functions described here must not call
120 \fBsetenv\fR(3)
121 from a parallel thread\&. It is recommended to only do calls to
122 \fBsetenv()\fR
123 from an early phase of the program when no other threads have been started\&.
124 .SH "HISTORY"
125 .PP
126 \fBsd_event_exit()\fR
127 and
128 \fBsd_event_get_exit_code()\fR
129 were added in version 229\&.
130 .SH "SEE ALSO"
131 .PP
132 \fBsystemd\fR(1), \fBsd-event\fR(3), \fBsd_event_new\fR(3), \fBsd_event_add_exit\fR(3), \fBsd_event_add_time\fR(3), \fBsd_event_add_signal\fR(3), \fBsd_event_add_io\fR(3), \fBsd_event_add_defer\fR(3), \fBsd_event_add_inotify\fR(3)