]>
Commit | Line | Data |
---|---|---|
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 | ||
96b2fb93 | 8 | Copyright © 2014 Zbigniew Jędrzejewski-Szmek |
3144ebca ZJS |
9 | --> |
10 | ||
dc83f27a | 11 | <refentry id="sd_event_add_signal" xmlns:xi="http://www.w3.org/2001/XInclude"> |
3144ebca ZJS |
12 | |
13 | <refentryinfo> | |
14 | <title>sd_event_add_signal</title> | |
15 | <productname>systemd</productname> | |
3144ebca ZJS |
16 | </refentryinfo> |
17 | ||
18 | <refmeta> | |
19 | <refentrytitle>sd_event_add_signal</refentrytitle> | |
20 | <manvolnum>3</manvolnum> | |
21 | </refmeta> | |
22 | ||
23 | <refnamediv> | |
24 | <refname>sd_event_add_signal</refname> | |
25 | <refname>sd_event_source_get_signal</refname> | |
dc83f27a | 26 | <refname>sd_event_signal_handler_t</refname> |
3144ebca | 27 | |
dc83f27a LP |
28 | <refpurpose>Add a UNIX process signal event source to an event |
29 | loop</refpurpose> | |
3144ebca ZJS |
30 | </refnamediv> |
31 | ||
32 | <refsynopsisdiv> | |
33 | <funcsynopsis> | |
dc83f27a LP |
34 | <funcsynopsisinfo>#include <systemd/sd-event.h></funcsynopsisinfo> |
35 | ||
36 | <funcsynopsisinfo><token>typedef</token> struct sd_event_source sd_event_source;</funcsynopsisinfo> | |
37 | ||
38 | <funcprototype> | |
39 | <funcdef>typedef int (*<function>sd_event_signal_handler_t</function>)</funcdef> | |
40 | <paramdef>sd_event_source *<parameter>s</parameter></paramdef> | |
41 | <paramdef>const struct signalfd_siginfo *<parameter>si</parameter></paramdef> | |
42 | <paramdef>void *<parameter>userdata</parameter></paramdef> | |
43 | </funcprototype> | |
3144ebca ZJS |
44 | |
45 | <funcprototype> | |
46 | <funcdef>int <function>sd_event_add_signal</function></funcdef> | |
47 | <paramdef>sd_event *<parameter>event</parameter></paramdef> | |
48 | <paramdef>sd_event_source **<parameter>source</parameter></paramdef> | |
49 | <paramdef>int <parameter>signal</parameter></paramdef> | |
50 | <paramdef>sd_event_signal_handler_t <parameter>handler</parameter></paramdef> | |
51 | <paramdef>void *<parameter>userdata</parameter></paramdef> | |
52 | </funcprototype> | |
53 | ||
3144ebca ZJS |
54 | <funcprototype> |
55 | <funcdef>int <function>sd_event_source_get_signal</function></funcdef> | |
56 | <paramdef>sd_event_source *<parameter>source</parameter></paramdef> | |
57 | </funcprototype> | |
58 | ||
59 | </funcsynopsis> | |
60 | </refsynopsisdiv> | |
61 | ||
62 | <refsect1> | |
63 | <title>Description</title> | |
64 | ||
dc83f27a LP |
65 | <para><function>sd_event_add_signal()</function> adds a new UNIX |
66 | process signal event source to an event loop. The event loop | |
67 | object is specified in the <parameter>event</parameter> parameter, | |
68 | and the event source object is returned in the | |
69 | <parameter>source</parameter> parameter. The | |
70 | <parameter>signal</parameter> parameter specifies the numeric | |
71 | signal to be handled (see <citerefentry | |
72 | project='man-pages'><refentrytitle>signal</refentrytitle><manvolnum>7</manvolnum></citerefentry>). | |
73 | The <parameter>handler</parameter> parameter must reference a | |
74 | function to call when the signal is received or be | |
75 | <constant>NULL</constant>. The handler function will be passed | |
76 | the <parameter>userdata</parameter> pointer, which may be chosen | |
3144ebca | 77 | freely by the caller. The handler also receives a pointer to a |
dc83f27a LP |
78 | <structname>signalfd_siginfo</structname> structure containing |
79 | information about the received signal. See <citerefentry | |
80 | project='man-pages'><refentrytitle>signalfd</refentrytitle><manvolnum>2</manvolnum></citerefentry> | |
922d948b | 81 | for further information.</para> |
3144ebca ZJS |
82 | |
83 | <para>Only a single handler may be installed for a specific | |
dc83f27a LP |
84 | signal. The signal will be unblocked by this call, and must be |
85 | blocked before this function is called in all threads (using | |
86 | <citerefentry | |
87 | project='man-pages'><refentrytitle>sigprocmask</refentrytitle><manvolnum>2</manvolnum></citerefentry>). If | |
88 | the handler is not specified (<parameter>handler</parameter> is | |
3144ebca | 89 | <constant>NULL</constant>), a default handler which causes the |
dc83f27a LP |
90 | program to exit cleanly will be used.</para> |
91 | ||
92 | <para>By default, the event source is enabled permanently | |
93 | (<constant>SD_EVENT_ON</constant>), but this may be changed with | |
3144ebca ZJS |
94 | <citerefentry><refentrytitle>sd_event_source_set_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry>. |
95 | If the handler function returns a negative error code, it will be | |
dc83f27a LP |
96 | disabled after the invocation, even if the |
97 | <constant>SD_EVENT_ON</constant> mode was requested before. | |
3144ebca ZJS |
98 | </para> |
99 | ||
dc83f27a LP |
100 | <para>To destroy an event source object use |
101 | <citerefentry><refentrytitle>sd_event_source_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
102 | but note that the event source is only removed from the event loop | |
103 | when all references to the event source are dropped. To make sure | |
f23e83b1 ZJS |
104 | an event source does not fire anymore, even if it is still referenced, |
105 | disable the event source using | |
106 | <citerefentry><refentrytitle>sd_event_source_set_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
107 | with <constant>SD_EVENT_OFF</constant>.</para> | |
dc83f27a | 108 | |
7f3fdb7f | 109 | <para>If the second parameter of |
f23e83b1 ZJS |
110 | <function>sd_event_add_signal()</function> is |
111 | <constant>NULL</constant> no reference to the event source object | |
112 | is returned. In this case the event source is considered | |
113 | "floating", and will be destroyed implicitly when the event loop | |
114 | itself is destroyed.</para> | |
115 | ||
116 | <para><function>sd_event_source_get_signal()</function> returns | |
117 | the configured signal number of an event source created previously | |
118 | with <function>sd_event_add_signal()</function>. It takes the | |
119 | event source object as the <parameter>source</parameter> | |
3144ebca | 120 | parameter.</para> |
3144ebca ZJS |
121 | </refsect1> |
122 | ||
123 | <refsect1> | |
124 | <title>Return Value</title> | |
125 | ||
126 | <para>On success, these functions return 0 or a positive | |
127 | integer. On failure, they return a negative errno-style error | |
f23e83b1 | 128 | code.</para> |
3144ebca ZJS |
129 | </refsect1> |
130 | ||
131 | <refsect1> | |
132 | <title>Errors</title> | |
133 | ||
134 | <para>Returned errors may indicate the following problems:</para> | |
135 | ||
136 | <variablelist> | |
137 | <varlistentry> | |
8474b70c | 138 | <term><constant>-ENOMEM</constant></term> |
3144ebca ZJS |
139 | |
140 | <listitem><para>Not enough memory to allocate an object.</para></listitem> | |
141 | </varlistentry> | |
142 | ||
143 | <varlistentry> | |
8474b70c | 144 | <term><constant>-EINVAL</constant></term> |
3144ebca ZJS |
145 | |
146 | <listitem><para>An invalid argument has been passed.</para></listitem> | |
3144ebca ZJS |
147 | </varlistentry> |
148 | ||
149 | <varlistentry> | |
8474b70c | 150 | <term><constant>-EBUSY</constant></term> |
3144ebca | 151 | |
a8eaaee7 | 152 | <listitem><para>A handler is already installed for this |
3144ebca | 153 | signal or the signal was not blocked previously.</para></listitem> |
3144ebca ZJS |
154 | </varlistentry> |
155 | ||
156 | <varlistentry> | |
8474b70c | 157 | <term><constant>-ESTALE</constant></term> |
3144ebca ZJS |
158 | |
159 | <listitem><para>The event loop is already terminated.</para></listitem> | |
3144ebca ZJS |
160 | </varlistentry> |
161 | ||
162 | <varlistentry> | |
8474b70c | 163 | <term><constant>-ECHILD</constant></term> |
3144ebca ZJS |
164 | |
165 | <listitem><para>The event loop has been created in a different process.</para></listitem> | |
3144ebca ZJS |
166 | </varlistentry> |
167 | ||
dc83f27a LP |
168 | <varlistentry> |
169 | <term><constant>-EDOM</constant></term> | |
3144ebca | 170 | |
dc83f27a LP |
171 | <listitem><para>The passed event source is not a signal event source.</para></listitem> |
172 | </varlistentry> | |
3144ebca | 173 | |
dc83f27a | 174 | </variablelist> |
3144ebca ZJS |
175 | </refsect1> |
176 | ||
dc83f27a LP |
177 | <xi:include href="libsystemd-pkgconfig.xml" /> |
178 | ||
3144ebca ZJS |
179 | <refsect1> |
180 | <title>See Also</title> | |
181 | ||
182 | <para> | |
183 | <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, | |
184 | <citerefentry><refentrytitle>sd-event</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
185 | <citerefentry><refentrytitle>sd_event_new</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
dc83f27a LP |
186 | <citerefentry><refentrytitle>sd_event_now</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
187 | <citerefentry><refentrytitle>sd_event_add_io</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
3144ebca | 188 | <citerefentry><refentrytitle>sd_event_add_time</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
edf25737 | 189 | <citerefentry><refentrytitle>sd_event_add_child</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
1eb54dc6 | 190 | <citerefentry><refentrytitle>sd_event_add_inotify</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
4dfefc19 | 191 | <citerefentry><refentrytitle>sd_event_add_defer</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
dc83f27a LP |
192 | <citerefentry><refentrytitle>sd_event_source_set_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
193 | <citerefentry><refentrytitle>sd_event_source_set_description</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
194 | <citerefentry><refentrytitle>sd_event_source_set_userdata</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
195 | <citerefentry project='man-pages'><refentrytitle>signal</refentrytitle><manvolnum>7</manvolnum></citerefentry>, | |
196 | <citerefentry project='man-pages'><refentrytitle>signalfd</refentrytitle><manvolnum>2</manvolnum></citerefentry> | |
3144ebca ZJS |
197 | </para> |
198 | </refsect1> | |
199 | ||
200 | </refentry> |