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">
6 This file is part of systemd.
8 Copyright 2014 Zbigniew Jędrzejewski-Szmek
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.
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.
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/>.
24 <refentry id=
"sd_event_add_child" conditional=
"ENABLE_KDBUS">
27 <title>sd_event_add_child
</title>
28 <productname>systemd
</productname>
32 <contrib>More text
</contrib>
33 <firstname>Zbigniew
</firstname>
34 <surname>Jędrzejewski-Szmek
</surname>
35 <email>zbyszek@in.waw.pl
</email>
41 <refentrytitle>sd_event_add_child
</refentrytitle>
42 <manvolnum>3</manvolnum>
46 <refname>sd_event_add_child
</refname>
47 <refname>sd_event_source_get_child_pid
</refname>
49 <refpurpose>Add a child state change event source to an event loop
</refpurpose>
54 <funcsynopsisinfo>#include
<systemd/sd-bus.h
></funcsynopsisinfo>
57 <funcdef>int
<function>sd_event_add_child
</function></funcdef>
58 <paramdef>sd_event *
<parameter>event
</parameter></paramdef>
59 <paramdef>sd_event_source **
<parameter>source
</parameter></paramdef>
60 <paramdef>pid_t
<parameter>pid
</parameter></paramdef>
61 <paramdef>int
<parameter>options
</parameter></paramdef>
62 <paramdef>sd_event_child_handler_t
<parameter>handler
</parameter></paramdef>
63 <paramdef>void *
<parameter>userdata
</parameter></paramdef>
67 <funcdef>typedef int (*
<function>sd_event_child_handler_t
</function>)
</funcdef>
68 <paramdef>sd_event_source *
<parameter>s
</parameter></paramdef>
69 <paramdef>const siginfo_t *
<parameter>si
</parameter></paramdef>
70 <paramdef>void *
<parameter>userdata
</parameter></paramdef>
74 <funcdef>int
<function>sd_event_source_get_child_pid
</function></funcdef>
75 <paramdef>sd_event_source *
<parameter>source
</parameter></paramdef>
76 <paramdef>pid_t *
<parameter>pid
</parameter></paramdef>
83 <title>Description
</title>
85 <para><function>sd_event_add_child()
</function> adds a new child
86 state change event source to an event loop object. The event loop
87 is specified in
<parameter>event
</parameter>, the event source is
88 returned in the
<parameter>source
</parameter> parameter. The
89 <parameter>pid
</parameter> parameter specifies the process to
90 watch. The
<parameter>handler
</parameter> must reference a
91 function to call when the process changes state. The handler
92 function will be passed the
<parameter>userdata
</parameter>
93 pointer, which may be chosen freely by the caller. The handler
94 also receives a pointer to a
<structname>const
95 siginfo_t
</structname> structure containing the information about
96 the event. The
<parameter>options
</parameter> parameter determines
97 which state changes will be watched for. It must contain an OR-ed
98 mask of
<constant>WEXITED
</constant> (watch for the child
99 terminating),
<constant>WSTOPPED
</constant> (watch for the child
100 being stopped by a signal), and
<constant>WCONTINUED
</constant>
101 (watch for the child being resumed by a signal). See
102 <citerefentry><refentrytitle>waitid
</refentrytitle><manvolnum>2</manvolnum></citerefentry>
103 for futher information.
</para>
105 <para>Only a single handler may be installed for a specific
106 child. The handler is enabled
107 for a single event (
<constant>SD_EVENT_ONESHOT
</constant>),
110 <citerefentry><refentrytitle>sd_event_source_set_enabled
</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
111 If the handler function returns a negative error code, it will be
112 disabled after the invocation, even if
113 <constant>SD_EVENT_ON
</constant> mode is set.
116 <para><function>sd_event_source_get_child_pid()
</function>
117 retrieves the configured
<parameter>pid
</parameter> of a child
118 state change event source created previously with
119 <function>sd_event_add_child()
</function>. It takes the event
120 source object as the
<parameter>source
</parameter> parameter and a
121 pointer to
<type>pid_t
</type> to return the result in.
126 <title>Return Value
</title>
128 <para>On success, these functions return
0 or a positive
129 integer. On failure, they return a negative errno-style error
134 <title>Errors
</title>
136 <para>Returned errors may indicate the following problems:
</para>
140 <term><constant>-ENOMEM
</constant></term>
142 <listitem><para>Not enough memory to allocate an object.
</para></listitem>
146 <term><constant>-EINVAL
</constant></term>
148 <listitem><para>An invalid argument has been passed. This includes
149 specyfing an empty mask in
<parameter>options
</parameter> or a mask
150 which constains values different than a combination of
151 <constant>WEXITED
</constant>,
<constant>WSTOPPED
</constant>, and
152 <constant>WCONTINUED
</constant>.
158 <term><constant>-EBUSY
</constant></term>
160 <listitem><para>An handler is already installed for this
161 child.
</para></listitem>
166 <term><constant>-ESTALE
</constant></term>
168 <listitem><para>The event loop is already terminated.
</para></listitem>
173 <term><constant>-ECHILD
</constant></term>
175 <listitem><para>The event loop has been created in a different process.
</para></listitem>
185 <para><function>sd_event_add_child()
</function> and the other functions
186 described here are available as a shared library, which can be
187 compiled and linked to with the
188 <constant>libsystemd
</constant> <citerefentry project='die-net'
><refentrytitle>pkg-config
</refentrytitle><manvolnum>1</manvolnum></citerefentry>
193 <title>See Also
</title>
196 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
197 <citerefentry><refentrytitle>sd-event
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
198 <citerefentry><refentrytitle>sd_event_new
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
199 <citerefentry><refentrytitle>sd_event_add_time
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
200 <citerefentry><refentrytitle>sd_event_add_signal
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
201 <citerefentry><refentrytitle>sd_event_add_defer
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
202 <citerefentry><refentrytitle>sd_event_source_set_enabled
</refentrytitle><manvolnum>3</manvolnum></citerefentry>