chiark / gitweb /
Export sd_bus_message_append_ap. It is renamed to sd_bus_message_appendv to follow...
[elogind.git] / man / sd_event_add_signal.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_signal" xmlns:xi="http://www.w3.org/2001/XInclude">
25
26   <refentryinfo>
27     <title>sd_event_add_signal</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_signal</refentrytitle>
42     <manvolnum>3</manvolnum>
43   </refmeta>
44
45   <refnamediv>
46     <refname>sd_event_add_signal</refname>
47     <refname>sd_event_source_get_signal</refname>
48     <refname>sd_event_signal_handler_t</refname>
49
50     <refpurpose>Add a UNIX process signal event source to an event
51     loop</refpurpose>
52   </refnamediv>
53
54   <refsynopsisdiv>
55     <funcsynopsis>
56       <funcsynopsisinfo>#include &lt;systemd/sd-event.h&gt;</funcsynopsisinfo>
57
58       <funcsynopsisinfo><token>typedef</token> struct sd_event_source sd_event_source;</funcsynopsisinfo>
59
60       <funcprototype>
61         <funcdef>typedef int (*<function>sd_event_signal_handler_t</function>)</funcdef>
62         <paramdef>sd_event_source *<parameter>s</parameter></paramdef>
63         <paramdef>const struct signalfd_siginfo *<parameter>si</parameter></paramdef>
64         <paramdef>void *<parameter>userdata</parameter></paramdef>
65       </funcprototype>
66
67       <funcprototype>
68         <funcdef>int <function>sd_event_add_signal</function></funcdef>
69         <paramdef>sd_event *<parameter>event</parameter></paramdef>
70         <paramdef>sd_event_source **<parameter>source</parameter></paramdef>
71         <paramdef>int <parameter>signal</parameter></paramdef>
72         <paramdef>sd_event_signal_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_signal</function></funcdef>
78         <paramdef>sd_event_source *<parameter>source</parameter></paramdef>
79       </funcprototype>
80
81     </funcsynopsis>
82   </refsynopsisdiv>
83
84   <refsect1>
85     <title>Description</title>
86
87     <para><function>sd_event_add_signal()</function> adds a new UNIX
88     process signal event source to an event loop. The event loop
89     object is specified in the <parameter>event</parameter> parameter,
90     and the event source object is returned in the
91     <parameter>source</parameter> parameter. The
92     <parameter>signal</parameter> parameter specifies the numeric
93     signal to be handled (see <citerefentry
94     project='man-pages'><refentrytitle>signal</refentrytitle><manvolnum>7</manvolnum></citerefentry>).
95     The <parameter>handler</parameter> parameter must reference a
96     function to call when the signal is received or be
97     <constant>NULL</constant>.  The handler function will be passed
98     the <parameter>userdata</parameter> pointer, which may be chosen
99     freely by the caller. The handler also receives a pointer to a
100     <structname>signalfd_siginfo</structname> structure containing
101     information about the received signal. See <citerefentry
102     project='man-pages'><refentrytitle>signalfd</refentrytitle><manvolnum>2</manvolnum></citerefentry>
103     for further information.</para>
104
105     <para>Only a single handler may be installed for a specific
106     signal. The signal will be unblocked by this call, and must be
107     blocked before this function is called in all threads (using
108     <citerefentry
109     project='man-pages'><refentrytitle>sigprocmask</refentrytitle><manvolnum>2</manvolnum></citerefentry>). If
110     the handler is not specified (<parameter>handler</parameter> is
111     <constant>NULL</constant>), a default handler which causes the
112     program to exit cleanly will be used.</para>
113
114     <para>By default, the event source is enabled permanently
115     (<constant>SD_EVENT_ON</constant>), but this may be changed with
116     <citerefentry><refentrytitle>sd_event_source_set_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
117     If the handler function returns a negative error code, it will be
118     disabled after the invocation, even if the
119     <constant>SD_EVENT_ON</constant> mode was requested before.
120     </para>
121
122     <para>To destroy an event source object use
123     <citerefentry><refentrytitle>sd_event_source_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
124     but note that the event source is only removed from the event loop
125     when all references to the event source are dropped. To make sure
126     an event source does not fire anymore, even if it is still referenced,
127     disable the event source using
128     <citerefentry><refentrytitle>sd_event_source_set_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry>
129     with <constant>SD_EVENT_OFF</constant>.</para>
130
131     <para>If the second parameter of
132     <function>sd_event_add_signal()</function> is
133     <constant>NULL</constant> no reference to the event source object
134     is returned. In this case the event source is considered
135     "floating", and will be destroyed implicitly when the event loop
136     itself is destroyed.</para>
137
138     <para><function>sd_event_source_get_signal()</function> returns
139     the configured signal number of an event source created previously
140     with <function>sd_event_add_signal()</function>. It takes the
141     event source object as the <parameter>source</parameter>
142     parameter.</para>
143   </refsect1>
144
145   <refsect1>
146     <title>Return Value</title>
147
148     <para>On success, these functions return 0 or a positive
149     integer. On failure, they return a negative errno-style error
150     code.</para>
151   </refsect1>
152
153   <refsect1>
154     <title>Errors</title>
155
156     <para>Returned errors may indicate the following problems:</para>
157
158     <variablelist>
159       <varlistentry>
160         <term><constant>-ENOMEM</constant></term>
161
162         <listitem><para>Not enough memory to allocate an object.</para></listitem>
163       </varlistentry>
164
165       <varlistentry>
166         <term><constant>-EINVAL</constant></term>
167
168         <listitem><para>An invalid argument has been passed.</para></listitem>
169       </varlistentry>
170
171       <varlistentry>
172         <term><constant>-EBUSY</constant></term>
173
174         <listitem><para>A handler is already installed for this
175         signal or the signal was not blocked previously.</para></listitem>
176       </varlistentry>
177
178       <varlistentry>
179         <term><constant>-ESTALE</constant></term>
180
181         <listitem><para>The event loop is already terminated.</para></listitem>
182       </varlistentry>
183
184       <varlistentry>
185         <term><constant>-ECHILD</constant></term>
186
187         <listitem><para>The event loop has been created in a different process.</para></listitem>
188       </varlistentry>
189
190       <varlistentry>
191         <term><constant>-EDOM</constant></term>
192
193         <listitem><para>The passed event source is not a signal event source.</para></listitem>
194       </varlistentry>
195
196     </variablelist>
197   </refsect1>
198
199   <xi:include href="libelogind-pkgconfig.xml" />
200
201   <refsect1>
202     <title>See Also</title>
203
204     <para>
205       <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
206       <citerefentry><refentrytitle>sd-event</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
207       <citerefentry><refentrytitle>sd_event_new</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
208       <citerefentry><refentrytitle>sd_event_now</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
209       <citerefentry><refentrytitle>sd_event_add_io</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
210       <citerefentry><refentrytitle>sd_event_add_time</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
211       <citerefentry><refentrytitle>sd_event_add_child</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
212       <citerefentry><refentrytitle>sd_event_add_defer</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
213       <citerefentry><refentrytitle>sd_event_source_set_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
214       <citerefentry><refentrytitle>sd_event_source_set_description</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
215       <citerefentry><refentrytitle>sd_event_source_set_userdata</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
216       <citerefentry project='man-pages'><refentrytitle>signal</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
217       <citerefentry project='man-pages'><refentrytitle>signalfd</refentrytitle><manvolnum>2</manvolnum></citerefentry>
218     </para>
219   </refsect1>
220
221 </refentry>