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