1SD_EVENT_ADD_SIGNAL(3)        sd_event_add_signal       SD_EVENT_ADD_SIGNAL(3)
2
3
4

NAME

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

SYNOPSIS

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

DESCRIPTION

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 must be blocked in all threads before this function is called
39       (using sigprocmask(2) or pthread_sigmask(3)).
40
41       By default, the event source is enabled permanently (SD_EVENT_ON), but
42       this may be changed with sd_event_source_set_enabled(3). If the handler
43       function returns a negative error code, it will be disabled after the
44       invocation, even if the SD_EVENT_ON mode was requested before.
45
46       To destroy an event source object use sd_event_source_unref(3), but
47       note that the event source is only removed from the event loop when all
48       references to the event source are dropped. To make sure an event
49       source does not fire anymore, even if it is still referenced, disable
50       the event source using sd_event_source_set_enabled(3) with
51       SD_EVENT_OFF.
52
53       If the second parameter of sd_event_add_signal() is NULL no reference
54       to the event source object is returned. In this case the event source
55       is considered "floating", and will be destroyed implicitly when the
56       event loop itself is destroyed.
57
58       If the handler parameter to sd_event_add_signal() is NULL, and the
59       event source fires, this will be considered a request to exit the event
60       loop. In this case, the userdata parameter, cast to an integer, is
61       passed as the exit code parameter to sd_event_exit(3).
62
63       sd_event_source_get_signal() returns the configured signal number of an
64       event source created previously with sd_event_add_signal(). It takes
65       the event source object as the source parameter.
66

RETURN VALUE

68       On success, these functions return 0 or a positive integer. On failure,
69       they return a negative errno-style error code.
70
71   Errors
72       Returned errors may indicate the following problems:
73
74       -ENOMEM
75           Not enough memory to allocate an object.
76
77       -EINVAL
78           An invalid argument has been passed.
79
80       -EBUSY
81           A handler is already installed for this signal or the signal was
82           not blocked previously.
83
84       -ESTALE
85           The event loop is already terminated.
86
87       -ECHILD
88           The event loop has been created in a different process.
89
90       -EDOM
91           The passed event source is not a signal event source.
92

NOTES

94       These APIs are implemented as a shared library, which can be compiled
95       and linked to with the libsystemd pkg-config(1) file.
96

SEE ALSO

98       systemd(1), sd-event(3), sd_event_new(3), sd_event_now(3),
99       sd_event_add_io(3), sd_event_add_time(3), sd_event_add_child(3),
100       sd_event_add_inotify(3), sd_event_add_defer(3),
101       sd_event_source_set_enabled(3), sd_event_source_set_description(3),
102       sd_event_source_set_userdata(3), sd_event_source_set_floating(3),
103       signal(7), signalfd(2), sigprocmask(2), pthread_sigmask(3)
104
105
106
107systemd 249                                             SD_EVENT_ADD_SIGNAL(3)
Impressum