]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/sd_event_add_signal.xml
journal-remote: remove unnecessary gnutls includes (#3895)
[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
f23e83b1
ZJS
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>
dc83f27a 130
7f3fdb7f 131 <para>If the second parameter of
f23e83b1
ZJS
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>
3144ebca 142 parameter.</para>
3144ebca
ZJS
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
f23e83b1 150 code.</para>
3144ebca
ZJS
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>
8474b70c 160 <term><constant>-ENOMEM</constant></term>
3144ebca
ZJS
161
162 <listitem><para>Not enough memory to allocate an object.</para></listitem>
163 </varlistentry>
164
165 <varlistentry>
8474b70c 166 <term><constant>-EINVAL</constant></term>
3144ebca
ZJS
167
168 <listitem><para>An invalid argument has been passed.</para></listitem>
3144ebca
ZJS
169 </varlistentry>
170
171 <varlistentry>
8474b70c 172 <term><constant>-EBUSY</constant></term>
3144ebca 173
a8eaaee7 174 <listitem><para>A handler is already installed for this
3144ebca 175 signal or the signal was not blocked previously.</para></listitem>
3144ebca
ZJS
176 </varlistentry>
177
178 <varlistentry>
8474b70c 179 <term><constant>-ESTALE</constant></term>
3144ebca
ZJS
180
181 <listitem><para>The event loop is already terminated.</para></listitem>
3144ebca
ZJS
182 </varlistentry>
183
184 <varlistentry>
8474b70c 185 <term><constant>-ECHILD</constant></term>
3144ebca
ZJS
186
187 <listitem><para>The event loop has been created in a different process.</para></listitem>
3144ebca
ZJS
188 </varlistentry>
189
dc83f27a
LP
190 <varlistentry>
191 <term><constant>-EDOM</constant></term>
3144ebca 192
dc83f27a
LP
193 <listitem><para>The passed event source is not a signal event source.</para></listitem>
194 </varlistentry>
3144ebca 195
dc83f27a 196 </variablelist>
3144ebca
ZJS
197 </refsect1>
198
dc83f27a
LP
199 <xi:include href="libsystemd-pkgconfig.xml" />
200
3144ebca
ZJS
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>,
dc83f27a
LP
208 <citerefentry><refentrytitle>sd_event_now</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
209 <citerefentry><refentrytitle>sd_event_add_io</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
3144ebca 210 <citerefentry><refentrytitle>sd_event_add_time</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
edf25737 211 <citerefentry><refentrytitle>sd_event_add_child</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
4dfefc19 212 <citerefentry><refentrytitle>sd_event_add_defer</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
dc83f27a
LP
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>
3144ebca
ZJS
218 </para>
219 </refsect1>
220
221</refentry>