From baf3fdec27f0b3a1f3d39c7def2a778824cbee51 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 28 Sep 2022 11:42:05 +0200 Subject: sd-event: add helper for exiting event loop on SIGTERM/SIGINT In many (most?) of our event loops we want to exit once SIGTERM/SIGINT is seen. Add a common helper for that, that does the right things in a single call. --- man/sd_event_set_signal_exit.xml | 101 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 man/sd_event_set_signal_exit.xml (limited to 'man/sd_event_set_signal_exit.xml') diff --git a/man/sd_event_set_signal_exit.xml b/man/sd_event_set_signal_exit.xml new file mode 100644 index 0000000000..e5e675beec --- /dev/null +++ b/man/sd_event_set_signal_exit.xml @@ -0,0 +1,101 @@ + + + + + + + + sd_event_set_signal_exit + systemd + + + + sd_event_set_signal_exit + 3 + + + + sd_event_set_signal_exit + + Automatically leave event loop on SIGINT and SIGTERM + + + + + #include <systemd/sd-event.h> + + + int sd_event_set_signal_exit + sd_event *event + int b + + + + + + + Description + + sd_event_set_signal_exit() may be used to ensure the event loop terminates + once a SIGINT or SIGTERM signal is received. It is a + convencience wrapper around invocations of + sd_event_add_signal3 + for both signals. The two signals are automatically added to the calling thread's signal mask (if a + program is multi-threaded care should be taken to either invoke this function before the first thread is + started or to manually block the two signals process-wide first). + + If the parameter b is specified as true, the event loop will terminate on + SIGINT and SIGTERM. If specified as false, it will no + longer. When this functionality is turned off the calling thread's signal mask is restored to match the + state before it was turned on, for the two signals. By default the two signals are not handled by the + event loop, and Linux' default signal handling for them is in effect. + + It's customary for UNIX programs to exit on either of these two signals, hence it's typically a + good idea to enable this functionality for the main event loop of a program. + + + + Return Value + + sd_event_set_signal_exit() returns a positive non-zero value when the setting + was successfully changed. It returns a zero when the specified setting was already in effect. On failure, + it returns a negative errno-style error code. + + + Errors + + Returned errors may indicate the following problems: + + + + + -ECHILD + + The event loop has been created in a different process. + + + + -EINVAL + + The passed event loop object was invalid. + + + + + + + + + + See Also + + + systemd1, + sd-event3, + sd_event_new3, + sd_event_add_signal3 + + + + -- cgit v1.2.1