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