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)). The handler parameter must reference a function to call
31 when the signal is received or be NULL. The handler function will be
32 passed the userdata pointer, which may be chosen freely by the caller.
33 The handler also receives a pointer to a signalfd_siginfo structure
34 containing information about the received signal. See signalfd(2) for
35 further information.
36
37 Only a single handler may be installed for a specific signal. The
38 signal will be unblocked by this call, and must be blocked before this
39 function is called in all threads (using sigprocmask(2)). If the
40 handler is not specified (handler is NULL), a default handler which
41 causes the program to exit cleanly will be used.
42
43 By default, the event source is enabled permanently (SD_EVENT_ON), but
44 this may be changed with sd_event_source_set_enabled(3). If the handler
45 function returns a negative error code, it will be disabled after the
46 invocation, even if the SD_EVENT_ON mode was requested before.
47
48 To destroy an event source object use sd_event_source_unref(3), but
49 note that the event source is only removed from the event loop when all
50 references to the event source are dropped. To make sure an event
51 source does not fire anymore, even if it is still referenced, disable
52 the event source using sd_event_source_set_enabled(3) with
53 SD_EVENT_OFF.
54
55 If the second parameter of sd_event_add_signal() is NULL no reference
56 to the event source object is returned. In this case the event source
57 is considered "floating", and will be destroyed implicitly when the
58 event loop itself is destroyed.
59
60 sd_event_source_get_signal() returns the configured signal number of an
61 event source created previously with sd_event_add_signal(). It takes
62 the event source object as the source parameter.
63
65 On success, these functions return 0 or a positive integer. On failure,
66 they return a negative errno-style error code.
67
68 Errors
69 Returned errors may indicate the following problems:
70
71 -ENOMEM
72 Not enough memory to allocate an object.
73
74 -EINVAL
75 An invalid argument has been passed.
76
77 -EBUSY
78 A handler is already installed for this signal or the signal was
79 not blocked previously.
80
81 -ESTALE
82 The event loop is already terminated.
83
84 -ECHILD
85 The event loop has been created in a different process.
86
87 -EDOM
88 The passed event source is not a signal event source.
89
91 These APIs are implemented as a shared library, which can be compiled
92 and linked to with the libsystemd pkg-config(1) file.
93
95 systemd(1), sd-event(3), sd_event_new(3), sd_event_now(3),
96 sd_event_add_io(3), sd_event_add_time(3), sd_event_add_child(3),
97 sd_event_add_inotify(3), sd_event_add_defer(3),
98 sd_event_source_set_enabled(3), sd_event_source_set_description(3),
99 sd_event_source_set_userdata(3), signal(7), signalfd(2)
100
101
102
103systemd 243 SD_EVENT_ADD_SIGNAL(3)