]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/sd_event_add_child.xml
Merge pull request #2071 from chaloulo/journal-upload-miss-logs
[thirdparty/systemd.git] / man / sd_event_add_child.xml
1 <?xml version='1.0'?> <!--*- Mode: nxml; nxml-child-indent: 2; indent-tabs-mode: nil -*-->
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4
5 <!--
6 This file is part of systemd.
7
8 Copyright 2014 Zbigniew Jędrzejewski-Szmek
9
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.
14
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.
19
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/>.
22 -->
23
24 <refentry id="sd_event_add_child" xmlns:xi="http://www.w3.org/2001/XInclude">
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>
48 <refname>sd_event_child_handler_t</refname>
49
50 <refpurpose>Add a child process state change event source to an event loop</refpurpose>
51 </refnamediv>
52
53 <refsynopsisdiv>
54 <funcsynopsis>
55 <funcsynopsisinfo>#include &lt;systemd/sd-event.h&gt;</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>
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
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
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
104 terminating), <constant>WSTOPPED</constant> (watch for the child
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>
109 for further information.</para>
110
111 <para>Only a single handler may be installed for a specific
112 child process. The handler is enabled for a single event
113 (<constant>SD_EVENT_ONESHOT</constant>), but this may be changed
114 with
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
117 disabled after the invocation, even if the
118 <constant>SD_EVENT_ON</constant> mode was requested before.
119 </para>
120
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
130 <para>If the second parameter of
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
151 <para><function>sd_event_source_get_child_pid()</function>
152 retrieves the configured PID of a child process state change event
153 source created previously with
154 <function>sd_event_add_child()</function>. It takes the event
155 source object as the <parameter>source</parameter> parameter and a
156 pointer to a <type>pid_t</type> variable to return the process ID
157 in.
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>
176 <term><constant>-ENOMEM</constant></term>
177
178 <listitem><para>Not enough memory to allocate an object.</para></listitem>
179 </varlistentry>
180
181 <varlistentry>
182 <term><constant>-EINVAL</constant></term>
183
184 <listitem><para>An invalid argument has been passed. This includes
185 specifying an empty mask in <parameter>options</parameter> or a mask
186 which contains values different than a combination of
187 <constant>WEXITED</constant>, <constant>WSTOPPED</constant>, and
188 <constant>WCONTINUED</constant>.
189 </para></listitem>
190
191 </varlistentry>
192
193 <varlistentry>
194 <term><constant>-EBUSY</constant></term>
195
196 <listitem><para>A handler is already installed for this
197 child process.</para></listitem>
198
199 </varlistentry>
200
201 <varlistentry>
202 <term><constant>-ESTALE</constant></term>
203
204 <listitem><para>The event loop is already terminated.</para></listitem>
205
206 </varlistentry>
207
208 <varlistentry>
209 <term><constant>-ECHILD</constant></term>
210
211 <listitem><para>The event loop has been created in a different process.</para></listitem>
212
213 </varlistentry>
214
215 <varlistentry>
216 <term><constant>-EDOM</constant></term>
217
218 <listitem><para>The passed event source is not a child process event source.</para></listitem>
219 </varlistentry>
220
221 </variablelist>
222 </refsect1>
223
224 <xi:include href="libsystemd-pkgconfig.xml" />
225
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>,
233 <citerefentry><refentrytitle>sd_event_now</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
234 <citerefentry><refentrytitle>sd_event_add_io</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
235 <citerefentry><refentrytitle>sd_event_add_time</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
236 <citerefentry><refentrytitle>sd_event_add_signal</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
237 <citerefentry><refentrytitle>sd_event_add_defer</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
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>
243 </para>
244 </refsect1>
245
246 </refentry>