sd_event_add_child.xml revision edf2573743b25273bee020230a60f1a054b8ec60
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson<?xml version='1.0'?> <!--*-nxml-*-->
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson<!--
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas GustafssonThis file is part of systemd.
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas GustafssonCopyright 2014 Zbigniew Jędrzejewski-Szmek
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafssonsystemd is free software; you can redistribute it and/or modify it
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafssonunder the terms of the GNU Lesser General Public License as published by
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafssonthe Free Software Foundation; either version 2.1 of the License, or
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson(at your option) any later version.
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafssonsystemd is distributed in the hope that it will be useful, but
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas GustafssonWITHOUT ANY WARRANTY; without even the implied warranty of
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas GustafssonMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas GustafssonLesser General Public License for more details.
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas GustafssonYou should have received a copy of the GNU Lesser General Public License
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafssonalong with systemd; If not, see <http://www.gnu.org/licenses/>.
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson-->
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson<refentry id="sd_event_add_child" conditional="ENABLE_KDBUS">
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson <refentryinfo>
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson <title>sd_event_add_child</title>
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson <productname>systemd</productname>
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson <authorgroup>
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson <author>
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson <contrib>More text</contrib>
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson <firstname>Zbigniew</firstname>
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson <surname>Jędrzejewski-Szmek</surname>
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson <email>zbyszek@in.waw.pl</email>
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson </author>
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson </authorgroup>
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson </refentryinfo>
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson <refmeta>
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson <refentrytitle>sd_event_add_child</refentrytitle>
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson <manvolnum>3</manvolnum>
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson </refmeta>
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson <refnamediv>
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson <refname>sd_event_add_child</refname>
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson <refname>sd_event_source_get_child_pid</refname>
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson <refpurpose>Add a child state change event source to an event loop</refpurpose>
a4520e13fbf5218b78db2934e76ea1d869bbcdfdBob Halley </refnamediv>
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson <refsynopsisdiv>
a4520e13fbf5218b78db2934e76ea1d869bbcdfdBob Halley <funcsynopsis>
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson <funcsynopsisinfo>#include &lt;systemd/sd-bus.h&gt;</funcsynopsisinfo>
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson <funcprototype>
a55d0a9080c8ef4117d2fc27f63220a56afb2434Andreas Gustafsson <funcdef>int <function>sd_event_add_child</function></funcdef>
8468c5a2ff04508ba503e664c76f8a36c274ccfaAndreas Gustafsson <paramdef>sd_event *<parameter>event</parameter></paramdef>
8468c5a2ff04508ba503e664c76f8a36c274ccfaAndreas Gustafsson <paramdef>sd_event_source **<parameter>source</parameter></paramdef>
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson <paramdef>pid_t <parameter>pid</parameter></paramdef>
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson <paramdef>int <parameter>options</parameter></paramdef>
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson <paramdef>sd_event_child_handler_t <parameter>handler</parameter></paramdef>
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson <paramdef>void *<parameter>userdata</parameter></paramdef>
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson </funcprototype>
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson <funcprototype>
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson <funcdef>typedef int (*<function>sd_event_child_handler_t</function>)</funcdef>
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson <paramdef>sd_event_source *<parameter>s</parameter></paramdef>
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson <paramdef>const siginfo_t *<parameter>si</parameter></paramdef>
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson <paramdef>void *<parameter>userdata</parameter></paramdef>
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson </funcprototype>
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson <funcprototype>
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson <funcdef>int <function>sd_event_source_get_child_pid</function></funcdef>
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson <paramdef>sd_event_source *<parameter>source</parameter></paramdef>
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson <paramdef>pid_t *<parameter>pid</parameter></paramdef>
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson </funcprototype>
e57d7e30f1a2e3fbd71d6cf0f18629c8a00bd9b8Andreas Gustafsson
e57d7e30f1a2e3fbd71d6cf0f18629c8a00bd9b8Andreas Gustafsson </funcsynopsis>
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson </refsynopsisdiv>
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson <refsect1>
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson <title>Description</title>
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson <para><function>sd_event_add_child()</function> adds a new child
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson state change event source to an event loop object. The event loop
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson is specified in <parameter>event</parameter>, the event source is
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson returned in the <parameter>source</parameter> parameter. The
a4520e13fbf5218b78db2934e76ea1d869bbcdfdBob Halley <parameter>pid</parameter> parameter specifies the process to
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson watch. The <parameter>handler</parameter> must reference a
a4520e13fbf5218b78db2934e76ea1d869bbcdfdBob Halley function to call when the process changes state. The handler
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson function will be passed the <parameter>userdata</parameter>
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson pointer, which may be chosen freely by the caller. The handler
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson also receives a pointer to a <structname>const
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson siginfo_t</structname> structure containing the information about
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson the event. The <parameter>options</parameter> parameter determines
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson which state changes will be watched for. It must contain an OR-ed
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson mask of <constant>WEXITED</constant> (watch for the child
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson terminating), <constant>WSTOPPED</constant> (watch for the child
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson being stopped by a signal), and <constant>WCONTINUED</constant>
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson (watch for the child being resumed by a signal). See
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson <citerefentry><refentrytitle>waitid</refentrytitle><manvolnum>2</manvolnum></citerefentry>
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson for futher information.</para>
a4520e13fbf5218b78db2934e76ea1d869bbcdfdBob Halley
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson <para>Only a single handler may be installed for a specific
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson child. The handler is enabled
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson for a single event (<constant>SD_EVENT_ONESHOT</constant>),
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson but this may be
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson changed with
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson <citerefentry><refentrytitle>sd_event_source_set_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson If the handler function returns a negative error code, it will be
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson disabled after the invocation, even if
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson <constant>SD_EVENT_ON</constant> mode is set.
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson </para>
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson <para><function>sd_event_source_get_child_pid()</function>
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson retrieves the configured <parameter>pid</parameter> of a child
a55d0a9080c8ef4117d2fc27f63220a56afb2434Andreas Gustafsson state change event source created previously with
a55d0a9080c8ef4117d2fc27f63220a56afb2434Andreas Gustafsson <function>sd_event_add_child()</function>. It takes the event
a55d0a9080c8ef4117d2fc27f63220a56afb2434Andreas Gustafsson source object as the <parameter>source</parameter> parameter and a
a55d0a9080c8ef4117d2fc27f63220a56afb2434Andreas Gustafsson pointer to <type>pid_t</type> to return the result in.
a55d0a9080c8ef4117d2fc27f63220a56afb2434Andreas Gustafsson </para>
a55d0a9080c8ef4117d2fc27f63220a56afb2434Andreas Gustafsson </refsect1>
a55d0a9080c8ef4117d2fc27f63220a56afb2434Andreas Gustafsson
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson <refsect1>
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson <title>Return Value</title>
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson <para>On success, these functions return 0 or a positive
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson integer. On failure, they return a negative errno-style error
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson code.</para>
559b10cc8f3e1dc4d93f55c9336f74839e9fa362Andreas Gustafsson </refsect1>
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson
ff64dc5d7f8072239e7c760e56551ad3c232da6fAndreas Gustafsson <refsect1>
<title>Errors</title>
<para>Returned errors may indicate the following problems:</para>
<variablelist>
<varlistentry>
<term><varname>-ENOMEM</varname></term>
<listitem><para>Not enough memory to allocate an object.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>-EINVAL</varname></term>
<listitem><para>An invalid argument has been passed. This includes
specyfing an empty mask in <parameter>options</parameter> or a mask
which constains values different than a combination of
<constant>WEXITED</constant>, <constant>WSTOPPED</constant>, and
<constant>WCONTINUED</constant>.
</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>-EBUSY</varname></term>
<listitem><para>An handler is already installed for this
child.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>-ESTALE</varname></term>
<listitem><para>The event loop is already terminated.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>-ECHILD</varname></term>
<listitem><para>The event loop has been created in a different process.</para></listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Notes</title>
<para><function>sd_event_add_child()</function> and the other functions
described here are available as a shared library, which can be
compiled and linked to with the
<constant>libsystemd</constant> <citerefentry project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
file.</para>
</refsect1>
<refsect1>
<title>See Also</title>
<para>
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd-event</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_event_new</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_event_add_time</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_event_add_signal</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
<citerefentry><refentrytitle>sd_event_source_set_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry>
</para>
</refsect1>
</refentry>