]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/sd_event_add_child.xml
Merge pull request #176 from filbranden/test_cgroup_mask1
[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 <!ENTITY % entities SYSTEM "custom-entities.ent" >
5 %entities;
6 ]>
7
8 <!--
9 This file is part of systemd.
10
11 Copyright 2014 Zbigniew Jędrzejewski-Szmek
12
13 systemd is free software; you can redistribute it and/or modify it
14 under the terms of the GNU Lesser General Public License as published by
15 the Free Software Foundation; either version 2.1 of the License, or
16 (at your option) any later version.
17
18 systemd is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Lesser General Public License for more details.
22
23 You should have received a copy of the GNU Lesser General Public License
24 along with systemd; If not, see <http://www.gnu.org/licenses/>.
25 -->
26
27 <refentry id="sd_event_add_child">
28
29 <refentryinfo>
30 <title>sd_event_add_child</title>
31 <productname>systemd</productname>
32
33 <authorgroup>
34 <author>
35 <contrib>More text</contrib>
36 <firstname>Zbigniew</firstname>
37 <surname>Jędrzejewski-Szmek</surname>
38 <email>zbyszek@in.waw.pl</email>
39 </author>
40 </authorgroup>
41 </refentryinfo>
42
43 <refmeta>
44 <refentrytitle>sd_event_add_child</refentrytitle>
45 <manvolnum>3</manvolnum>
46 </refmeta>
47
48 <refnamediv>
49 <refname>sd_event_add_child</refname>
50 <refname>sd_event_source_get_child_pid</refname>
51
52 <refpurpose>Add a child state change event source to an event loop</refpurpose>
53 </refnamediv>
54
55 <refsynopsisdiv>
56 <funcsynopsis>
57 <funcsynopsisinfo>#include &lt;systemd/sd-bus.h&gt;</funcsynopsisinfo>
58
59 <funcprototype>
60 <funcdef>int <function>sd_event_add_child</function></funcdef>
61 <paramdef>sd_event *<parameter>event</parameter></paramdef>
62 <paramdef>sd_event_source **<parameter>source</parameter></paramdef>
63 <paramdef>pid_t <parameter>pid</parameter></paramdef>
64 <paramdef>int <parameter>options</parameter></paramdef>
65 <paramdef>sd_event_child_handler_t <parameter>handler</parameter></paramdef>
66 <paramdef>void *<parameter>userdata</parameter></paramdef>
67 </funcprototype>
68
69 <funcprototype>
70 <funcdef>typedef int (*<function>sd_event_child_handler_t</function>)</funcdef>
71 <paramdef>sd_event_source *<parameter>s</parameter></paramdef>
72 <paramdef>const siginfo_t *<parameter>si</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 state change event source to an event loop object. The event loop
90 is specified in <parameter>event</parameter>, the event source is
91 returned in the <parameter>source</parameter> parameter. The
92 <parameter>pid</parameter> parameter specifies the process to
93 watch. The <parameter>handler</parameter> must reference a
94 function to call when the process changes state. The handler
95 function will be passed the <parameter>userdata</parameter>
96 pointer, which may be chosen freely by the caller. The handler
97 also receives a pointer to a <structname>const
98 siginfo_t</structname> structure containing the information about
99 the event. The <parameter>options</parameter> parameter determines
100 which state changes will be watched for. It must contain an OR-ed
101 mask of <constant>WEXITED</constant> (watch for the child
102 terminating), <constant>WSTOPPED</constant> (watch for the child
103 being stopped by a signal), and <constant>WCONTINUED</constant>
104 (watch for the child being resumed by a signal). See
105 <citerefentry><refentrytitle>waitid</refentrytitle><manvolnum>2</manvolnum></citerefentry>
106 for further information.</para>
107
108 <para>Only a single handler may be installed for a specific
109 child. The handler is enabled
110 for a single event (<constant>SD_EVENT_ONESHOT</constant>),
111 but this may be
112 changed with
113 <citerefentry><refentrytitle>sd_event_source_set_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
114 If the handler function returns a negative error code, it will be
115 disabled after the invocation, even if
116 <constant>SD_EVENT_ON</constant> mode is set.
117 </para>
118
119 <para><function>sd_event_source_get_child_pid()</function>
120 retrieves the configured <parameter>pid</parameter> of a child
121 state change event source created previously with
122 <function>sd_event_add_child()</function>. It takes the event
123 source object as the <parameter>source</parameter> parameter and a
124 pointer to <type>pid_t</type> to return the result in.
125 </para>
126 </refsect1>
127
128 <refsect1>
129 <title>Return Value</title>
130
131 <para>On success, these functions return 0 or a positive
132 integer. On failure, they return a negative errno-style error
133 code.</para>
134 </refsect1>
135
136 <refsect1>
137 <title>Errors</title>
138
139 <para>Returned errors may indicate the following problems:</para>
140
141 <variablelist>
142 <varlistentry>
143 <term><constant>-ENOMEM</constant></term>
144
145 <listitem><para>Not enough memory to allocate an object.</para></listitem>
146 </varlistentry>
147
148 <varlistentry>
149 <term><constant>-EINVAL</constant></term>
150
151 <listitem><para>An invalid argument has been passed. This includes
152 specifying an empty mask in <parameter>options</parameter> or a mask
153 which contains values different than a combination of
154 <constant>WEXITED</constant>, <constant>WSTOPPED</constant>, and
155 <constant>WCONTINUED</constant>.
156 </para></listitem>
157
158 </varlistentry>
159
160 <varlistentry>
161 <term><constant>-EBUSY</constant></term>
162
163 <listitem><para>An handler is already installed for this
164 child.</para></listitem>
165
166 </varlistentry>
167
168 <varlistentry>
169 <term><constant>-ESTALE</constant></term>
170
171 <listitem><para>The event loop is already terminated.</para></listitem>
172
173 </varlistentry>
174
175 <varlistentry>
176 <term><constant>-ECHILD</constant></term>
177
178 <listitem><para>The event loop has been created in a different process.</para></listitem>
179
180 </varlistentry>
181
182 </variablelist>
183 </refsect1>
184
185 <refsect1>
186 <title>Notes</title>
187
188 <para><function>sd_event_add_child()</function> and the other functions
189 described here are available as a shared library, which can be
190 compiled and linked to with the
191 <constant>libsystemd</constant> <citerefentry project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
192 file.</para>
193 </refsect1>
194
195 <refsect1>
196 <title>See Also</title>
197
198 <para>
199 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
200 <citerefentry><refentrytitle>sd-event</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
201 <citerefentry><refentrytitle>sd_event_new</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
202 <citerefentry><refentrytitle>sd_event_add_time</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
203 <citerefentry><refentrytitle>sd_event_add_signal</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
204 <citerefentry><refentrytitle>sd_event_add_defer</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
205 <citerefentry><refentrytitle>sd_event_source_set_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry>
206 </para>
207 </refsect1>
208
209 </refentry>