]>
Commit | Line | Data |
---|---|---|
514094f9 | 1 | <?xml version='1.0'?> |
3a54a157 | 2 | <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" |
eea10b26 | 3 | "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"> |
db9ecf05 | 4 | <!-- SPDX-License-Identifier: LGPL-2.1-or-later --> |
3144ebca | 5 | |
dc83f27a | 6 | <refentry id="sd_event_add_signal" xmlns:xi="http://www.w3.org/2001/XInclude"> |
3144ebca ZJS |
7 | |
8 | <refentryinfo> | |
9 | <title>sd_event_add_signal</title> | |
10 | <productname>systemd</productname> | |
3144ebca ZJS |
11 | </refentryinfo> |
12 | ||
13 | <refmeta> | |
14 | <refentrytitle>sd_event_add_signal</refentrytitle> | |
15 | <manvolnum>3</manvolnum> | |
16 | </refmeta> | |
17 | ||
18 | <refnamediv> | |
19 | <refname>sd_event_add_signal</refname> | |
20 | <refname>sd_event_source_get_signal</refname> | |
dc83f27a | 21 | <refname>sd_event_signal_handler_t</refname> |
897448bd | 22 | <refname>SD_EVENT_SIGNAL_PROCMASK</refname> |
3144ebca | 23 | |
dc83f27a LP |
24 | <refpurpose>Add a UNIX process signal event source to an event |
25 | loop</refpurpose> | |
3144ebca ZJS |
26 | </refnamediv> |
27 | ||
28 | <refsynopsisdiv> | |
29 | <funcsynopsis> | |
dc83f27a LP |
30 | <funcsynopsisinfo>#include <systemd/sd-event.h></funcsynopsisinfo> |
31 | ||
32 | <funcsynopsisinfo><token>typedef</token> struct sd_event_source sd_event_source;</funcsynopsisinfo> | |
33 | ||
897448bd LP |
34 | <funcsynopsisinfo><constant>SD_EVENT_SIGNAL_PROCMASK</constant></funcsynopsisinfo> |
35 | ||
dc83f27a LP |
36 | <funcprototype> |
37 | <funcdef>typedef int (*<function>sd_event_signal_handler_t</function>)</funcdef> | |
38 | <paramdef>sd_event_source *<parameter>s</parameter></paramdef> | |
39 | <paramdef>const struct signalfd_siginfo *<parameter>si</parameter></paramdef> | |
40 | <paramdef>void *<parameter>userdata</parameter></paramdef> | |
41 | </funcprototype> | |
3144ebca ZJS |
42 | |
43 | <funcprototype> | |
44 | <funcdef>int <function>sd_event_add_signal</function></funcdef> | |
45 | <paramdef>sd_event *<parameter>event</parameter></paramdef> | |
46 | <paramdef>sd_event_source **<parameter>source</parameter></paramdef> | |
47 | <paramdef>int <parameter>signal</parameter></paramdef> | |
48 | <paramdef>sd_event_signal_handler_t <parameter>handler</parameter></paramdef> | |
49 | <paramdef>void *<parameter>userdata</parameter></paramdef> | |
50 | </funcprototype> | |
51 | ||
3144ebca ZJS |
52 | <funcprototype> |
53 | <funcdef>int <function>sd_event_source_get_signal</function></funcdef> | |
54 | <paramdef>sd_event_source *<parameter>source</parameter></paramdef> | |
55 | </funcprototype> | |
3144ebca ZJS |
56 | </funcsynopsis> |
57 | </refsynopsisdiv> | |
58 | ||
59 | <refsect1> | |
60 | <title>Description</title> | |
61 | ||
897448bd LP |
62 | <para><function>sd_event_add_signal()</function> adds a new UNIX process signal event source to an event |
63 | loop. The event loop object is specified in the <parameter>event</parameter> parameter, and the event | |
64 | source object is returned in the <parameter>source</parameter> parameter. The | |
65 | <parameter>signal</parameter> parameter specifies the numeric signal to be handled (see <citerefentry | |
9809a788 ZJS |
66 | project='man-pages'><refentrytitle>signal</refentrytitle><manvolnum>7</manvolnum></citerefentry>).</para> |
67 | ||
68 | <para>The <parameter>handler</parameter> parameter is a function to call when the signal is received or | |
69 | <constant>NULL</constant>. The handler function will be passed the <parameter>userdata</parameter> | |
70 | pointer, which may be chosen freely by the caller. The handler also receives a pointer to a | |
71 | <structname>signalfd_siginfo</structname> structure containing information about the received signal. See | |
897448bd LP |
72 | <citerefentry |
73 | project='man-pages'><refentrytitle>signalfd</refentrytitle><manvolnum>2</manvolnum></citerefentry> for | |
74 | further information. The handler may return negative to signal an error (see below), other return values | |
75 | are ignored. If <parameter>handler</parameter> is <constant>NULL</constant>, a default handler that calls | |
9809a788 ZJS |
76 | <citerefentry><refentrytitle>sd_event_exit</refentrytitle><manvolnum>3</manvolnum></citerefentry> will be |
77 | used.</para> | |
3144ebca | 78 | |
68765d94 LP |
79 | <para>Only a single handler may be installed for a specific signal. The signal must be blocked in all |
80 | threads before this function is called (using <citerefentry | |
81 | project='man-pages'><refentrytitle>sigprocmask</refentrytitle><manvolnum>2</manvolnum></citerefentry> or | |
dc83f27a | 82 | <citerefentry |
897448bd LP |
83 | project='man-pages'><refentrytitle>pthread_sigmask</refentrytitle><manvolnum>3</manvolnum></citerefentry>). For |
84 | convenience, if the special flag <constant>SD_EVENT_SIGNAL_PROCMASK</constant> is ORed into the specified | |
85 | signal the signal will be automatically masked as necessary, for the calling thread. Note that this only | |
86 | works reliably if the signal is already masked in all other threads of the process, or if there are no | |
87 | other threads at the moment of invocation.</para> | |
88 | ||
89 | <para>By default, the event source is enabled permanently (<constant>SD_EVENT_ON</constant>), but this | |
90 | may be changed with | |
3144ebca | 91 | <citerefentry><refentrytitle>sd_event_source_set_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry>. |
897448bd LP |
92 | If the handler function returns a negative error code, it will either be disabled after the invocation, |
93 | even if the <constant>SD_EVENT_ON</constant> mode was requested before, or it will cause the loop to | |
94 | terminate, see | |
9809a788 | 95 | <citerefentry><refentrytitle>sd_event_source_set_exit_on_failure</refentrytitle><manvolnum>3</manvolnum></citerefentry>. |
3144ebca ZJS |
96 | </para> |
97 | ||
dc83f27a LP |
98 | <para>To destroy an event source object use |
99 | <citerefentry><refentrytitle>sd_event_source_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
100 | but note that the event source is only removed from the event loop | |
101 | when all references to the event source are dropped. To make sure | |
f23e83b1 ZJS |
102 | an event source does not fire anymore, even if it is still referenced, |
103 | disable the event source using | |
104 | <citerefentry><refentrytitle>sd_event_source_set_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
105 | with <constant>SD_EVENT_OFF</constant>.</para> | |
dc83f27a | 106 | |
7f3fdb7f | 107 | <para>If the second parameter of |
f23e83b1 ZJS |
108 | <function>sd_event_add_signal()</function> is |
109 | <constant>NULL</constant> no reference to the event source object | |
110 | is returned. In this case the event source is considered | |
111 | "floating", and will be destroyed implicitly when the event loop | |
112 | itself is destroyed.</para> | |
113 | ||
b9350e70 LP |
114 | <para>If the <parameter>handler</parameter> parameter to <function>sd_event_add_signal()</function> is |
115 | <constant>NULL</constant>, and the event source fires, this will be considered a request to exit the | |
116 | event loop. In this case, the <parameter>userdata</parameter> parameter, cast to an integer, is passed as | |
117 | the exit code parameter to | |
118 | <citerefentry><refentrytitle>sd_event_exit</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para> | |
119 | ||
f23e83b1 ZJS |
120 | <para><function>sd_event_source_get_signal()</function> returns |
121 | the configured signal number of an event source created previously | |
122 | with <function>sd_event_add_signal()</function>. It takes the | |
123 | event source object as the <parameter>source</parameter> | |
3144ebca | 124 | parameter.</para> |
3144ebca ZJS |
125 | </refsect1> |
126 | ||
127 | <refsect1> | |
128 | <title>Return Value</title> | |
129 | ||
130 | <para>On success, these functions return 0 or a positive | |
131 | integer. On failure, they return a negative errno-style error | |
f23e83b1 | 132 | code.</para> |
3144ebca | 133 | |
b1de39de ZJS |
134 | <refsect2> |
135 | <title>Errors</title> | |
3144ebca | 136 | |
b1de39de | 137 | <para>Returned errors may indicate the following problems:</para> |
3144ebca | 138 | |
b1de39de ZJS |
139 | <variablelist> |
140 | <varlistentry> | |
141 | <term><constant>-ENOMEM</constant></term> | |
3144ebca | 142 | |
b1de39de ZJS |
143 | <listitem><para>Not enough memory to allocate an object.</para></listitem> |
144 | </varlistentry> | |
3144ebca | 145 | |
b1de39de ZJS |
146 | <varlistentry> |
147 | <term><constant>-EINVAL</constant></term> | |
3144ebca | 148 | |
b1de39de ZJS |
149 | <listitem><para>An invalid argument has been passed.</para></listitem> |
150 | </varlistentry> | |
3144ebca | 151 | |
b1de39de ZJS |
152 | <varlistentry> |
153 | <term><constant>-EBUSY</constant></term> | |
3144ebca | 154 | |
b1de39de ZJS |
155 | <listitem><para>A handler is already installed for this |
156 | signal or the signal was not blocked previously.</para></listitem> | |
157 | </varlistentry> | |
3144ebca | 158 | |
b1de39de ZJS |
159 | <varlistentry> |
160 | <term><constant>-ESTALE</constant></term> | |
3144ebca | 161 | |
b1de39de ZJS |
162 | <listitem><para>The event loop is already terminated.</para></listitem> |
163 | </varlistentry> | |
3144ebca | 164 | |
b1de39de ZJS |
165 | <varlistentry> |
166 | <term><constant>-ECHILD</constant></term> | |
3144ebca | 167 | |
2eeff0f4 | 168 | <listitem><para>The event loop has been created in a different process, library or module instance.</para></listitem> |
b1de39de | 169 | </varlistentry> |
3144ebca | 170 | |
b1de39de ZJS |
171 | <varlistentry> |
172 | <term><constant>-EDOM</constant></term> | |
3144ebca | 173 | |
b1de39de ZJS |
174 | <listitem><para>The passed event source is not a signal event source.</para></listitem> |
175 | </varlistentry> | |
3144ebca | 176 | |
b1de39de ZJS |
177 | </variablelist> |
178 | </refsect2> | |
3144ebca ZJS |
179 | </refsect1> |
180 | ||
dc83f27a LP |
181 | <xi:include href="libsystemd-pkgconfig.xml" /> |
182 | ||
69106f47 AK |
183 | <refsect1> |
184 | <title>History</title> | |
00f95506 AK |
185 | <para><function>sd_event_add_signal()</function>, |
186 | <function>sd_event_signal_handler_t()</function>, and | |
187 | <function>sd_event_source_get_signal()</function> were added in version 217.</para> | |
69106f47 AK |
188 | </refsect1> |
189 | ||
3144ebca ZJS |
190 | <refsect1> |
191 | <title>See Also</title> | |
192 | ||
13a69c12 DT |
193 | <para><simplelist type="inline"> |
194 | <member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> | |
195 | <member><citerefentry><refentrytitle>sd-event</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> | |
196 | <member><citerefentry><refentrytitle>sd_event_new</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> | |
197 | <member><citerefentry><refentrytitle>sd_event_now</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> | |
198 | <member><citerefentry><refentrytitle>sd_event_add_io</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> | |
199 | <member><citerefentry><refentrytitle>sd_event_add_time</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> | |
200 | <member><citerefentry><refentrytitle>sd_event_add_child</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> | |
201 | <member><citerefentry><refentrytitle>sd_event_add_inotify</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> | |
202 | <member><citerefentry><refentrytitle>sd_event_add_defer</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> | |
203 | <member><citerefentry><refentrytitle>sd_event_source_set_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> | |
204 | <member><citerefentry><refentrytitle>sd_event_source_set_description</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> | |
205 | <member><citerefentry><refentrytitle>sd_event_source_set_userdata</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> | |
206 | <member><citerefentry><refentrytitle>sd_event_source_set_floating</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> | |
207 | <member><citerefentry project='man-pages'><refentrytitle>signal</refentrytitle><manvolnum>7</manvolnum></citerefentry></member> | |
208 | <member><citerefentry project='man-pages'><refentrytitle>signalfd</refentrytitle><manvolnum>2</manvolnum></citerefentry></member> | |
209 | <member><citerefentry project='man-pages'><refentrytitle>sigprocmask</refentrytitle><manvolnum>2</manvolnum></citerefentry></member> | |
210 | <member><citerefentry project='man-pages'><refentrytitle>pthread_sigmask</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> | |
211 | </simplelist></para> | |
3144ebca ZJS |
212 | </refsect1> |
213 | ||
214 | </refentry> |