Debian Codegraph @

upstream/debian-unstable/man3/sd_event_add_signal.3

raw
1 '\" t
2 .TH "SD_EVENT_ADD_SIGNAL" "3" "" "systemd 261~rc3" "sd_event_add_signal"
3 .\" -----------------------------------------------------------------
4 .\" * Define some portability stuff
5 .\" -----------------------------------------------------------------
6 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 .\" http://bugs.debian.org/507673
8 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
9 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 .ie \n(.g .ds Aq \(aq
11 .el .ds Aq '
12 .\" -----------------------------------------------------------------
13 .\" * set default formatting
14 .\" -----------------------------------------------------------------
15 .\" disable hyphenation
16 .nh
17 .\" disable justification (adjust text to left margin only)
18 .ad l
19 .\" -----------------------------------------------------------------
20 .\" * MAIN CONTENT STARTS HERE *
21 .\" -----------------------------------------------------------------
22 .SH "NAME"
23 sd_event_add_signal, sd_event_source_get_signal, sd_event_signal_handler_t, SD_EVENT_SIGNAL_PROCMASK \- Add a UNIX process signal event source to an event loop
24 .SH "SYNOPSIS"
25 .sp
26 .ft B
27 .nf
28 #include <systemd/sd\-event\&.h>
29 .fi
30 .ft
31 .sp
32 .ft B
33 .nf
34 typedef struct sd_event_source sd_event_source;
35 .fi
36 .ft
37 .sp
38 .ft B
39 .nf
40 \fBSD_EVENT_SIGNAL_PROCMASK\fR
41 .fi
42 .ft
43 .HP \w'typedef\ int\ (*sd_event_signal_handler_t)('u
44 .BI "typedef int (*sd_event_signal_handler_t)(sd_event_source\ *" "s" ", const\ struct\ signalfd_siginfo\ *" "si" ", void\ *" "userdata" ");"
45 .HP \w'int\ sd_event_add_signal('u
46 .BI "int sd_event_add_signal(sd_event\ *" "event" ", sd_event_source\ **" "source" ", int\ " "signal" ", sd_event_signal_handler_t\ " "handler" ", void\ *" "userdata" ");"
47 .HP \w'int\ sd_event_source_get_signal('u
48 .BI "int sd_event_source_get_signal(sd_event_source\ *" "source" ");"
49 .SH "DESCRIPTION"
50 .PP
51 \fBsd_event_add_signal()\fR
52 adds a new UNIX process signal event source to an event loop\&. The event loop object is specified in the
53 \fIevent\fR
54 parameter, and the event source object is returned in the
55 \fIsource\fR
56 parameter\&. The
57 \fIsignal\fR
58 parameter specifies the numeric signal to be handled (see
59 \fBsignal\fR(7))\&.
60 .PP
61 The
62 \fIhandler\fR
63 parameter is a function to call when the signal is received or
64 \fBNULL\fR\&. The handler function will be passed the
65 \fIuserdata\fR
66 pointer, which may be chosen freely by the caller\&. The handler also receives a pointer to a
67 signalfd_siginfo
68 structure containing information about the received signal\&. See
69 \fBsignalfd\fR(2)
70 for further information\&. The handler may return negative to signal an error (see below), other return values are ignored\&. If
71 \fIhandler\fR
72 is
73 \fBNULL\fR, a default handler that calls
74 \fBsd_event_exit\fR(3)
75 will be used\&.
76 .PP
77 Only a single handler may be installed for a specific signal\&. The signal must be blocked in all threads before this function is called (using
78 \fBsigprocmask\fR(2)
79 or
80 \fBpthread_sigmask\fR(3))\&. For convenience, if the special flag
81 \fBSD_EVENT_SIGNAL_PROCMASK\fR
82 is ORed into the specified signal the signal will be automatically masked as necessary, for the calling thread\&. Note that this only works reliably if the signal is already masked in all other threads of the process, or if there are no other threads at the moment of invocation\&.
83 .PP
84 By default, the event source is enabled permanently (\fBSD_EVENT_ON\fR), but this may be changed with
85 \fBsd_event_source_set_enabled\fR(3)\&. If the handler function returns a negative error code, it will either be disabled after the invocation, even if the
86 \fBSD_EVENT_ON\fR
87 mode was requested before, or it will cause the loop to terminate, see
88 \fBsd_event_source_set_exit_on_failure\fR(3)\&.
89 .PP
90 To destroy an event source object use
91 \fBsd_event_source_unref\fR(3), but note that the event source is only removed from the event loop when all references to the event source are dropped\&. To make sure an event source does not fire anymore, even if it is still referenced, disable the event source using
92 \fBsd_event_source_set_enabled\fR(3)
93 with
94 \fBSD_EVENT_OFF\fR\&.
95 .PP
96 If the second parameter of
97 \fBsd_event_add_signal()\fR
98 is
99 \fBNULL\fR
100 no reference to the event source object is returned\&. In this case, the event source is considered "floating", and will be destroyed implicitly when the event loop itself is destroyed\&.
101 .PP
102 If the
103 \fIhandler\fR
104 parameter to
105 \fBsd_event_add_signal()\fR
106 is
107 \fBNULL\fR, and the event source fires, this will be considered a request to exit the event loop\&. In this case, the
108 \fIuserdata\fR
109 parameter, cast to an integer, is passed as the exit code parameter to
110 \fBsd_event_exit\fR(3)\&.
111 .PP
112 \fBsd_event_source_get_signal()\fR
113 returns the configured signal number of an event source created previously with
114 \fBsd_event_add_signal()\fR\&. It takes the event source object as the
115 \fIsource\fR
116 parameter\&.
117 .SH "RETURN VALUE"
118 .PP
119 On success, these functions return 0 or a positive integer\&. On failure, they return a negative errno\-style error code\&.
120 .SS "Errors"
121 .PP
122 Returned errors may indicate the following problems:
123 .PP
124 \fB\-ENOMEM\fR
125 .RS 4
126 Not enough memory to allocate an object\&.
127 .RE
128 .PP
129 \fB\-EINVAL\fR
130 .RS 4
131 An invalid argument has been passed\&.
132 .RE
133 .PP
134 \fB\-EBUSY\fR
135 .RS 4
136 A handler is already installed for this signal or the signal was not blocked previously\&.
137 .RE
138 .PP
139 \fB\-ESTALE\fR
140 .RS 4
141 The event loop is already terminated\&.
142 .RE
143 .PP
144 \fB\-ECHILD\fR
145 .RS 4
146 The event loop has been created in a different process, library or module instance\&.
147 .RE
148 .PP
149 \fB\-EDOM\fR
150 .RS 4
151 The passed event source is not a signal event source\&.
152 .RE
153 .SH "NOTES"
154 .PP
155 Functions described here are available as a shared library, which can be compiled against and linked to with the
156 \fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
157 file\&.
158 .PP
159 The code described here uses
160 \fBgetenv\fR(3), which is declared to be not multi\-thread\-safe\&. This means that the code calling the functions described here must not call
161 \fBsetenv\fR(3)
162 from a parallel thread\&. It is recommended to only do calls to
163 \fBsetenv()\fR
164 from an early phase of the program when no other threads have been started\&.
165 .SH "HISTORY"
166 .PP
167 \fBsd_event_add_signal()\fR,
168 \fBsd_event_signal_handler_t()\fR, and
169 \fBsd_event_source_get_signal()\fR
170 were added in version 217\&.
171 .SH "SEE ALSO"
172 .PP
173 \fBsystemd\fR(1), \fBsd-event\fR(3), \fBsd_event_new\fR(3), \fBsd_event_now\fR(3), \fBsd_event_add_io\fR(3), \fBsd_event_add_time\fR(3), \fBsd_event_add_child\fR(3), \fBsd_event_add_inotify\fR(3), \fBsd_event_add_defer\fR(3), \fBsd_event_source_set_enabled\fR(3), \fBsd_event_source_set_description\fR(3), \fBsd_event_source_set_userdata\fR(3), \fBsd_event_source_set_floating\fR(3), \fBsignal\fR(7), \fBsignalfd\fR(2), \fBsigprocmask\fR(2), \fBpthread_sigmask\fR(3)