]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/sd_event_add_signal.xml
Merge pull request #2224 from keszybz/analyze-verify-warning
[thirdparty/systemd.git] / man / sd_event_add_signal.xml
CommitLineData
3802a3d3 1<?xml version='1.0'?> <!--*- Mode: nxml; nxml-child-indent: 2; indent-tabs-mode: nil -*-->
3144ebca 2<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
12b42c76 3"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
3144ebca
ZJS
4
5<!--
5de0ccff 6 This file is part of systemd.
3144ebca 7
5de0ccff 8 Copyright 2014 Zbigniew Jędrzejewski-Szmek
3144ebca 9
5de0ccff
ZJS
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.
3144ebca 14
5de0ccff
ZJS
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.
3144ebca 19
5de0ccff
ZJS
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/>.
3144ebca
ZJS
22-->
23
dc83f27a 24<refentry id="sd_event_add_signal" xmlns:xi="http://www.w3.org/2001/XInclude">
3144ebca
ZJS
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>
dc83f27a 48 <refname>sd_event_signal_handler_t</refname>
3144ebca 49
dc83f27a
LP
50 <refpurpose>Add a UNIX process signal event source to an event
51 loop</refpurpose>
3144ebca
ZJS
52 </refnamediv>
53
54 <refsynopsisdiv>
55 <funcsynopsis>
dc83f27a
LP
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>
3144ebca
ZJS
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
3144ebca
ZJS
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
dc83f27a
LP
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
3144ebca 99 freely by the caller. The handler also receives a pointer to a
dc83f27a
LP
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>
922d948b 103 for further information.</para>
3144ebca
ZJS
104
105 <para>Only a single handler may be installed for a specific
dc83f27a
LP
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
3144ebca 111 <constant>NULL</constant>), a default handler which causes the
dc83f27a
LP
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
3144ebca
ZJS
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
dc83f27a
LP
118 disabled after the invocation, even if the
119 <constant>SD_EVENT_ON</constant> mode was requested before.
3144ebca
ZJS
120 </para>
121
dc83f27a
LP
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
3144ebca 137 <para><function>sd_event_source_get_signal()</function> retrieves
dc83f27a
LP
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>
3144ebca
ZJS
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>
8474b70c 161 <term><constant>-ENOMEM</constant></term>
3144ebca
ZJS
162
163 <listitem><para>Not enough memory to allocate an object.</para></listitem>
164 </varlistentry>
165
166 <varlistentry>
8474b70c 167 <term><constant>-EINVAL</constant></term>
3144ebca
ZJS
168
169 <listitem><para>An invalid argument has been passed.</para></listitem>
170
171 </varlistentry>
172
173 <varlistentry>
8474b70c 174 <term><constant>-EBUSY</constant></term>
3144ebca 175
a8eaaee7 176 <listitem><para>A handler is already installed for this
3144ebca
ZJS
177 signal or the signal was not blocked previously.</para></listitem>
178
179 </varlistentry>
180
181 <varlistentry>
8474b70c 182 <term><constant>-ESTALE</constant></term>
3144ebca
ZJS
183
184 <listitem><para>The event loop is already terminated.</para></listitem>
185
186 </varlistentry>
187
188 <varlistentry>
8474b70c 189 <term><constant>-ECHILD</constant></term>
3144ebca
ZJS
190
191 <listitem><para>The event loop has been created in a different process.</para></listitem>
192
193 </varlistentry>
194
dc83f27a
LP
195 <varlistentry>
196 <term><constant>-EDOM</constant></term>
3144ebca 197
dc83f27a
LP
198 <listitem><para>The passed event source is not a signal event source.</para></listitem>
199 </varlistentry>
3144ebca 200
dc83f27a 201 </variablelist>
3144ebca
ZJS
202 </refsect1>
203
dc83f27a
LP
204 <xi:include href="libsystemd-pkgconfig.xml" />
205
3144ebca
ZJS
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>,
dc83f27a
LP
213 <citerefentry><refentrytitle>sd_event_now</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
214 <citerefentry><refentrytitle>sd_event_add_io</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
3144ebca 215 <citerefentry><refentrytitle>sd_event_add_time</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
edf25737 216 <citerefentry><refentrytitle>sd_event_add_child</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
4dfefc19 217 <citerefentry><refentrytitle>sd_event_add_defer</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
dc83f27a
LP
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>
3144ebca
ZJS
223 </para>
224 </refsect1>
225
226</refentry>