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