]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/sd_event_add_signal.xml
Merge pull request #1964 from poettering/sd-event-man
[thirdparty/systemd.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 when there's still a
127 reference to it kept, consider setting the event source to
128 <constant>SD_EVENT_OFF</constant> with
129 <citerefentry><refentrytitle>sd_event_source_set_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para>
130
131 <para>If the the second parameter of
132 <function>sd_event_add_signal()</function> is passed as NULL no
133 reference to the event source object is returned. In this case the
134 event source is considered "floating", and will be destroyed
135 implicitly when the event loop itself is destroyed.</para>
136
137 <para><function>sd_event_source_get_signal()</function> retrieves
138 the configured UNIX process signal number of a signal event source
139 created previously with
140 <function>sd_event_add_signal()</function>. It takes the event
141 source object as the <parameter>source</parameter>
142 parameter.</para>
143
144 </refsect1>
145
146 <refsect1>
147 <title>Return Value</title>
148
149 <para>On success, these functions return 0 or a positive
150 integer. On failure, they return a negative errno-style error
151 code. </para>
152 </refsect1>
153
154 <refsect1>
155 <title>Errors</title>
156
157 <para>Returned errors may indicate the following problems:</para>
158
159 <variablelist>
160 <varlistentry>
161 <term><constant>-ENOMEM</constant></term>
162
163 <listitem><para>Not enough memory to allocate an object.</para></listitem>
164 </varlistentry>
165
166 <varlistentry>
167 <term><constant>-EINVAL</constant></term>
168
169 <listitem><para>An invalid argument has been passed.</para></listitem>
170
171 </varlistentry>
172
173 <varlistentry>
174 <term><constant>-EBUSY</constant></term>
175
176 <listitem><para>A handler is already installed for this
177 signal or the signal was not blocked previously.</para></listitem>
178
179 </varlistentry>
180
181 <varlistentry>
182 <term><constant>-ESTALE</constant></term>
183
184 <listitem><para>The event loop is already terminated.</para></listitem>
185
186 </varlistentry>
187
188 <varlistentry>
189 <term><constant>-ECHILD</constant></term>
190
191 <listitem><para>The event loop has been created in a different process.</para></listitem>
192
193 </varlistentry>
194
195 <varlistentry>
196 <term><constant>-EDOM</constant></term>
197
198 <listitem><para>The passed event source is not a signal event source.</para></listitem>
199 </varlistentry>
200
201 </variablelist>
202 </refsect1>
203
204 <xi:include href="libsystemd-pkgconfig.xml" />
205
206 <refsect1>
207 <title>See Also</title>
208
209 <para>
210 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
211 <citerefentry><refentrytitle>sd-event</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
212 <citerefentry><refentrytitle>sd_event_new</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
213 <citerefentry><refentrytitle>sd_event_now</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
214 <citerefentry><refentrytitle>sd_event_add_io</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
215 <citerefentry><refentrytitle>sd_event_add_time</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
216 <citerefentry><refentrytitle>sd_event_add_child</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
217 <citerefentry><refentrytitle>sd_event_add_defer</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
218 <citerefentry><refentrytitle>sd_event_source_set_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
219 <citerefentry><refentrytitle>sd_event_source_set_description</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
220 <citerefentry><refentrytitle>sd_event_source_set_userdata</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
221 <citerefentry project='man-pages'><refentrytitle>signal</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
222 <citerefentry project='man-pages'><refentrytitle>signalfd</refentrytitle><manvolnum>2</manvolnum></citerefentry>
223 </para>
224 </refsect1>
225
226 </refentry>