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