]>
Commit | Line | Data |
---|---|---|
514094f9 | 1 | <?xml version='1.0'?> |
3a54a157 ZJS |
2 | <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" |
3 | "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> | |
0307f791 | 4 | <!-- SPDX-License-Identifier: LGPL-2.1+ --> |
edf25737 | 5 | |
dc83f27a | 6 | <refentry id="sd_event_add_child" xmlns:xi="http://www.w3.org/2001/XInclude"> |
edf25737 ZJS |
7 | |
8 | <refentryinfo> | |
9 | <title>sd_event_add_child</title> | |
10 | <productname>systemd</productname> | |
edf25737 ZJS |
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> | |
dc83f27a | 21 | <refname>sd_event_child_handler_t</refname> |
edf25737 | 22 | |
dc83f27a | 23 | <refpurpose>Add a child process state change event source to an event loop</refpurpose> |
edf25737 ZJS |
24 | </refnamediv> |
25 | ||
26 | <refsynopsisdiv> | |
27 | <funcsynopsis> | |
dc83f27a LP |
28 | <funcsynopsisinfo>#include <systemd/sd-event.h></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> | |
edf25737 ZJS |
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 | ||
edf25737 ZJS |
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 | |
dc83f27a LP |
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 | |
edf25737 | 77 | terminating), <constant>WSTOPPED</constant> (watch for the child |
dc83f27a LP |
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> | |
922d948b | 82 | for further information.</para> |
edf25737 ZJS |
83 | |
84 | <para>Only a single handler may be installed for a specific | |
dc83f27a LP |
85 | child process. The handler is enabled for a single event |
86 | (<constant>SD_EVENT_ONESHOT</constant>), but this may be changed | |
87 | with | |
edf25737 ZJS |
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 | |
dc83f27a LP |
90 | disabled after the invocation, even if the |
91 | <constant>SD_EVENT_ON</constant> mode was requested before. | |
edf25737 ZJS |
92 | </para> |
93 | ||
dc83f27a LP |
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 | ||
7f3fdb7f | 103 | <para>If the second parameter of |
dc83f27a LP |
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 | ||
edf25737 | 124 | <para><function>sd_event_source_get_child_pid()</function> |
dc83f27a LP |
125 | retrieves the configured PID of a child process state change event |
126 | source created previously with | |
edf25737 ZJS |
127 | <function>sd_event_add_child()</function>. It takes the event |
128 | source object as the <parameter>source</parameter> parameter and a | |
dc83f27a LP |
129 | pointer to a <type>pid_t</type> variable to return the process ID |
130 | in. | |
edf25737 ZJS |
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> | |
edf25737 | 140 | |
b1de39de ZJS |
141 | <refsect2> |
142 | <title>Errors</title> | |
edf25737 | 143 | |
b1de39de | 144 | <para>Returned errors may indicate the following problems:</para> |
edf25737 | 145 | |
b1de39de ZJS |
146 | <variablelist> |
147 | <varlistentry> | |
148 | <term><constant>-ENOMEM</constant></term> | |
edf25737 | 149 | |
b1de39de ZJS |
150 | <listitem><para>Not enough memory to allocate an object.</para></listitem> |
151 | </varlistentry> | |
edf25737 | 152 | |
b1de39de ZJS |
153 | <varlistentry> |
154 | <term><constant>-EINVAL</constant></term> | |
edf25737 | 155 | |
b1de39de ZJS |
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> | |
edf25737 | 162 | |
b1de39de | 163 | </varlistentry> |
edf25737 | 164 | |
b1de39de ZJS |
165 | <varlistentry> |
166 | <term><constant>-EBUSY</constant></term> | |
edf25737 | 167 | |
b1de39de ZJS |
168 | <listitem><para>A handler is already installed for this |
169 | child process.</para></listitem> | |
edf25737 | 170 | |
b1de39de | 171 | </varlistentry> |
edf25737 | 172 | |
b1de39de ZJS |
173 | <varlistentry> |
174 | <term><constant>-ESTALE</constant></term> | |
edf25737 | 175 | |
b1de39de | 176 | <listitem><para>The event loop is already terminated.</para></listitem> |
edf25737 | 177 | |
b1de39de | 178 | </varlistentry> |
edf25737 | 179 | |
b1de39de ZJS |
180 | <varlistentry> |
181 | <term><constant>-ECHILD</constant></term> | |
edf25737 | 182 | |
b1de39de | 183 | <listitem><para>The event loop has been created in a different process.</para></listitem> |
edf25737 | 184 | |
b1de39de | 185 | </varlistentry> |
edf25737 | 186 | |
b1de39de ZJS |
187 | <varlistentry> |
188 | <term><constant>-EDOM</constant></term> | |
edf25737 | 189 | |
b1de39de ZJS |
190 | <listitem><para>The passed event source is not a child process event source.</para></listitem> |
191 | </varlistentry> | |
edf25737 | 192 | |
b1de39de ZJS |
193 | </variablelist> |
194 | </refsect2> | |
edf25737 ZJS |
195 | </refsect1> |
196 | ||
dc83f27a LP |
197 | <xi:include href="libsystemd-pkgconfig.xml" /> |
198 | ||
edf25737 ZJS |
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>, | |
dc83f27a LP |
206 | <citerefentry><refentrytitle>sd_event_now</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
207 | <citerefentry><refentrytitle>sd_event_add_io</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
edf25737 ZJS |
208 | <citerefentry><refentrytitle>sd_event_add_time</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
209 | <citerefentry><refentrytitle>sd_event_add_signal</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
1eb54dc6 | 210 | <citerefentry><refentrytitle>sd_event_add_inotify</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
4dfefc19 | 211 | <citerefentry><refentrytitle>sd_event_add_defer</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
dc83f27a LP |
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> | |
edf25737 ZJS |
217 | </para> |
218 | </refsect1> | |
219 | ||
220 | </refentry> |