1SD_EVENT_ADD_SIGNAL(3) sd_event_add_signal SD_EVENT_ADD_SIGNAL(3)
2
3
4
6 sd_event_add_signal, sd_event_source_get_signal,
7 sd_event_signal_handler_t - Add a UNIX process signal event source to
8 an event loop
9
11 #include <systemd/sd-event.h>
12
13 typedef struct sd_event_source sd_event_source;
14
15 typedef int (*sd_event_signal_handler_t)(sd_event_source *s,
16 const struct signalfd_siginfo *si,
17 void *userdata);
18
19 int sd_event_add_signal(sd_event *event, sd_event_source **source,
20 int signal, sd_event_signal_handler_t handler,
21 void *userdata);
22
23 int sd_event_source_get_signal(sd_event_source *source);
24
26 sd_event_add_signal() adds a new UNIX process signal event source to an
27 event loop. The event loop object is specified in the event parameter,
28 and the event source object is returned in the source parameter. The
29 signal parameter specifies the numeric signal to be handled (see
30 signal(7)).
31
32 The handler parameter is a function to call when the signal is received
33 or NULL. The handler function will be passed the userdata pointer,
34 which may be chosen freely by the caller. The handler also receives a
35 pointer to a signalfd_siginfo structure containing information about
36 the received signal. See signalfd(2) for further information. The
37 handler may return negative to signal an error (see below), other
38 return values are ignored. If handler is NULL, a default handler that
39 calls sd_event_exit(3) will be used.
40
41 Only a single handler may be installed for a specific signal. The
42 signal must be blocked in all threads before this function is called
43 (using sigprocmask(2) or pthread_sigmask(3)).
44
45 By default, the event source is enabled permanently (SD_EVENT_ON), but
46 this may be changed with sd_event_source_set_enabled(3). If the handler
47 function returns a negative error code, it will either be disabled
48 after the invocation, even if the SD_EVENT_ON mode was requested
49 before, or it will cause the loop to terminate, see
50 sd_event_source_set_exit_on_failure(3).
51
52 To destroy an event source object use sd_event_source_unref(3), but
53 note that the event source is only removed from the event loop when all
54 references to the event source are dropped. To make sure an event
55 source does not fire anymore, even if it is still referenced, disable
56 the event source using sd_event_source_set_enabled(3) with
57 SD_EVENT_OFF.
58
59 If the second parameter of sd_event_add_signal() is NULL no reference
60 to the event source object is returned. In this case the event source
61 is considered "floating", and will be destroyed implicitly when the
62 event loop itself is destroyed.
63
64 If the handler parameter to sd_event_add_signal() is NULL, and the
65 event source fires, this will be considered a request to exit the event
66 loop. In this case, the userdata parameter, cast to an integer, is
67 passed as the exit code parameter to sd_event_exit(3).
68
69 sd_event_source_get_signal() returns the configured signal number of an
70 event source created previously with sd_event_add_signal(). It takes
71 the event source object as the source parameter.
72
74 On success, these functions return 0 or a positive integer. On failure,
75 they return a negative errno-style error code.
76
77 Errors
78 Returned errors may indicate the following problems:
79
80 -ENOMEM
81 Not enough memory to allocate an object.
82
83 -EINVAL
84 An invalid argument has been passed.
85
86 -EBUSY
87 A handler is already installed for this signal or the signal was
88 not blocked previously.
89
90 -ESTALE
91 The event loop is already terminated.
92
93 -ECHILD
94 The event loop has been created in a different process.
95
96 -EDOM
97 The passed event source is not a signal event source.
98
100 These APIs are implemented as a shared library, which can be compiled
101 and linked to with the libsystemd pkg-config(1) file.
102
104 systemd(1), sd-event(3), sd_event_new(3), sd_event_now(3),
105 sd_event_add_io(3), sd_event_add_time(3), sd_event_add_child(3),
106 sd_event_add_inotify(3), sd_event_add_defer(3),
107 sd_event_source_set_enabled(3), sd_event_source_set_description(3),
108 sd_event_source_set_userdata(3), sd_event_source_set_floating(3),
109 signal(7), signalfd(2), sigprocmask(2), pthread_sigmask(3)
110
111
112
113systemd 251 SD_EVENT_ADD_SIGNAL(3)