]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/sd_event_add_child.xml
travis: add 5 more fuzz targets
[thirdparty/systemd.git] / man / sd_event_add_child.xml
1 <?xml version='1.0'?>
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4 <!-- SPDX-License-Identifier: LGPL-2.1+ -->
5
6 <refentry id="sd_event_add_child" xmlns:xi="http://www.w3.org/2001/XInclude">
7
8 <refentryinfo>
9 <title>sd_event_add_child</title>
10 <productname>systemd</productname>
11 </refentryinfo>
12
13 <refmeta>
14 <refentrytitle>sd_event_add_child</refentrytitle>
15 <manvolnum>3</manvolnum>
16 </refmeta>
17
18 <refnamediv>
19 <refname>sd_event_add_child</refname>
20 <refname>sd_event_source_get_child_pid</refname>
21 <refname>sd_event_child_handler_t</refname>
22
23 <refpurpose>Add a child process state change event source to an event loop</refpurpose>
24 </refnamediv>
25
26 <refsynopsisdiv>
27 <funcsynopsis>
28 <funcsynopsisinfo>#include &lt;systemd/sd-event.h&gt;</funcsynopsisinfo>
29
30 <funcsynopsisinfo><token>typedef</token> struct sd_event_source sd_event_source;</funcsynopsisinfo>
31
32 <funcprototype>
33 <funcdef>typedef int (*<function>sd_event_child_handler_t</function>)</funcdef>
34 <paramdef>sd_event_source *<parameter>s</parameter></paramdef>
35 <paramdef>const siginfo_t *<parameter>si</parameter></paramdef>
36 <paramdef>void *<parameter>userdata</parameter></paramdef>
37 </funcprototype>
38
39 <funcprototype>
40 <funcdef>int <function>sd_event_add_child</function></funcdef>
41 <paramdef>sd_event *<parameter>event</parameter></paramdef>
42 <paramdef>sd_event_source **<parameter>source</parameter></paramdef>
43 <paramdef>pid_t <parameter>pid</parameter></paramdef>
44 <paramdef>int <parameter>options</parameter></paramdef>
45 <paramdef>sd_event_child_handler_t <parameter>handler</parameter></paramdef>
46 <paramdef>void *<parameter>userdata</parameter></paramdef>
47 </funcprototype>
48
49 <funcprototype>
50 <funcdef>int <function>sd_event_source_get_child_pid</function></funcdef>
51 <paramdef>sd_event_source *<parameter>source</parameter></paramdef>
52 <paramdef>pid_t *<parameter>pid</parameter></paramdef>
53 </funcprototype>
54
55 </funcsynopsis>
56 </refsynopsisdiv>
57
58 <refsect1>
59 <title>Description</title>
60
61 <para><function>sd_event_add_child()</function> adds a new child
62 process state change event source to an event loop. The event loop
63 object is specified in the <parameter>event</parameter> parameter,
64 the event source object is returned in the
65 <parameter>source</parameter> parameter. The
66 <parameter>pid</parameter> parameter specifies the PID of the
67 process to watch. The <parameter>handler</parameter> must
68 reference a function to call when the process changes state. The
69 handler function will be passed the
70 <parameter>userdata</parameter> pointer, which may be chosen
71 freely by the caller. The handler also receives a pointer to a
72 <structname>siginfo_t</structname> structure containing
73 information about the child process event. The
74 <parameter>options</parameter> parameter determines which state
75 changes will be watched for. It must contain an OR-ed mask of
76 <constant>WEXITED</constant> (watch for the child process
77 terminating), <constant>WSTOPPED</constant> (watch for the child
78 process being stopped by a signal), and
79 <constant>WCONTINUED</constant> (watch for the child process being
80 resumed by a signal). See <citerefentry
81 project='man-pages'><refentrytitle>waitid</refentrytitle><manvolnum>2</manvolnum></citerefentry>
82 for further information.</para>
83
84 <para>Only a single handler may be installed for a specific
85 child process. The handler is enabled for a single event
86 (<constant>SD_EVENT_ONESHOT</constant>), but this may be changed
87 with
88 <citerefentry><refentrytitle>sd_event_source_set_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
89 If the handler function returns a negative error code, it will be
90 disabled after the invocation, even if the
91 <constant>SD_EVENT_ON</constant> mode was requested before.
92 </para>
93
94 <para>To destroy an event source object use
95 <citerefentry><refentrytitle>sd_event_source_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
96 but note that the event source is only removed from the event loop
97 when all references to the event source are dropped. To make sure
98 an event source does not fire anymore, even when there's still a
99 reference to it kept, consider setting the event source to
100 <constant>SD_EVENT_OFF</constant> with
101 <citerefentry><refentrytitle>sd_event_source_set_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para>
102
103 <para>If the second parameter of
104 <function>sd_event_add_child()</function> is passed as NULL no
105 reference to the event source object is returned. In this case the
106 event source is considered "floating", and will be destroyed
107 implicitly when the event loop itself is destroyed.</para>
108
109 <para>Note that the <parameter>handler</parameter> function is
110 invoked at a time where the child process is not reaped yet (and
111 thus still is exposed as a zombie process by the kernel). However,
112 the child will be reaped automatically after the function
113 returns. Child processes for which no child process state change
114 event sources are installed will not be reaped by the event loop
115 implementation.</para>
116
117 <para>If both a child process state change event source and a
118 <constant>SIGCHLD</constant> signal event source is installed in
119 the same event loop, the configured event source priorities decide
120 which event source is dispatched first. If the signal handler is
121 processed first, it should leave the child processes for which
122 child process state change event sources are installed unreaped.</para>
123
124 <para><function>sd_event_source_get_child_pid()</function>
125 retrieves the configured PID of a child process state change event
126 source created previously with
127 <function>sd_event_add_child()</function>. It takes the event
128 source object as the <parameter>source</parameter> parameter and a
129 pointer to a <type>pid_t</type> variable to return the process ID
130 in.
131 </para>
132 </refsect1>
133
134 <refsect1>
135 <title>Return Value</title>
136
137 <para>On success, these functions return 0 or a positive
138 integer. On failure, they return a negative errno-style error
139 code.</para>
140
141 <refsect2>
142 <title>Errors</title>
143
144 <para>Returned errors may indicate the following problems:</para>
145
146 <variablelist>
147 <varlistentry>
148 <term><constant>-ENOMEM</constant></term>
149
150 <listitem><para>Not enough memory to allocate an object.</para></listitem>
151 </varlistentry>
152
153 <varlistentry>
154 <term><constant>-EINVAL</constant></term>
155
156 <listitem><para>An invalid argument has been passed. This includes
157 specifying an empty mask in <parameter>options</parameter> or a mask
158 which contains values different than a combination of
159 <constant>WEXITED</constant>, <constant>WSTOPPED</constant>, and
160 <constant>WCONTINUED</constant>.
161 </para></listitem>
162
163 </varlistentry>
164
165 <varlistentry>
166 <term><constant>-EBUSY</constant></term>
167
168 <listitem><para>A handler is already installed for this
169 child process.</para></listitem>
170
171 </varlistentry>
172
173 <varlistentry>
174 <term><constant>-ESTALE</constant></term>
175
176 <listitem><para>The event loop is already terminated.</para></listitem>
177
178 </varlistentry>
179
180 <varlistentry>
181 <term><constant>-ECHILD</constant></term>
182
183 <listitem><para>The event loop has been created in a different process.</para></listitem>
184
185 </varlistentry>
186
187 <varlistentry>
188 <term><constant>-EDOM</constant></term>
189
190 <listitem><para>The passed event source is not a child process event source.</para></listitem>
191 </varlistentry>
192
193 </variablelist>
194 </refsect2>
195 </refsect1>
196
197 <xi:include href="libsystemd-pkgconfig.xml" />
198
199 <refsect1>
200 <title>See Also</title>
201
202 <para>
203 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
204 <citerefentry><refentrytitle>sd-event</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
205 <citerefentry><refentrytitle>sd_event_new</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
206 <citerefentry><refentrytitle>sd_event_now</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
207 <citerefentry><refentrytitle>sd_event_add_io</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
208 <citerefentry><refentrytitle>sd_event_add_time</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
209 <citerefentry><refentrytitle>sd_event_add_signal</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
210 <citerefentry><refentrytitle>sd_event_add_inotify</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
211 <citerefentry><refentrytitle>sd_event_add_defer</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
212 <citerefentry><refentrytitle>sd_event_source_set_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
213 <citerefentry><refentrytitle>sd_event_source_set_priority</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
214 <citerefentry><refentrytitle>sd_event_source_set_userdata</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
215 <citerefentry><refentrytitle>sd_event_source_set_description</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
216 <citerefentry project='man-pages'><refentrytitle>waitid</refentrytitle><manvolnum>2</manvolnum></citerefentry>
217 </para>
218 </refsect1>
219
220 </refentry>