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