sd_event_set_signal_exit(3) — Linux manual page


SD_EVENT...NAL_EXIT(3)  sd_event_set_signal_exit  SD_EVENT...NAL_EXIT(3)

NAME         top

       sd_event_set_signal_exit - Automatically leave event loop on

SYNOPSIS         top

       #include <systemd/sd-event.h>

       int sd_event_set_signal_exit(sd_event *event, int b);

DESCRIPTION         top

       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
       convenience wrapper around invocations of sd_event_add_signal(3)
       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         top

       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.

       Returned errors may indicate the following problems:

           The event loop has been created in a different process,
           library or module instance.

           Added in version 252.

           The passed event loop object was invalid.

           Added in version 252.

NOTES         top

       Functions described here are available as a shared library, which
       can be compiled against and linked to with the
       libsystemd pkg-config(1) file.

       The code described here uses getenv(3), which is declared to be
       not multi-thread-safe. This means that the code calling the
       functions described here must not call setenv(3) from a parallel
       thread. It is recommended to only do calls to setenv() from an
       early phase of the program when no other threads have been

HISTORY         top

       sd_event_set_signal_exit() was added in version 252.

SEE ALSO         top

       systemd(1), sd-event(3), sd_event_new(3), sd_event_add_signal(3)

COLOPHON         top

       This page is part of the systemd (systemd system and service
       manager) project.  Information about the project can be found at
       ⟨⟩.  If you have
       a bug report for this manual page, see
       This page was obtained from the project's upstream Git repository
       ⟨⟩ on 2023-12-22.  (At that
       time, the date of the most recent commit that was found in the
       repository was 2023-12-22.)  If you discover any rendering
       problems in this HTML version of the page, or you believe there
       is a better or more up-to-date source for the page, or you have
       corrections or improvements to the information in this COLOPHON
       (which is not part of the original manual page), send a mail to

systemd 255                                       SD_EVENT...NAL_EXIT(3)

Pages that refer to this page: systemd.directives(7)systemd.index(7)