---
name: "sd_event_set_signal_exit"
section: "3"
platform: "linux"
package: "systemd-libs"
version: "262.1-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/sd_event_set_signal_exit"
---

# sd\_event\_set\_signal\_exit(3)

Automatically leave event loop on SIGINT and SIGTERM

## NAME

sd\_event\_set\_signal\_exit - Automatically leave event loop on **SIGINT** and **SIGTERM**

## SYNOPSIS

```
#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 convenience wrapper around invocations of [**sd\_event\_add\_signal**(3)](/sd_event_add_signal/3.md) 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 is customary for UNIX programs to exit on either of these two signals, hence it is 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, library or module instance.

Added in version 252.

**-EINVAL**

The passed event loop object was invalid.

Added in version 252.

## NOTES

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

All functions listed here are thread-agnostic and only a single thread may operate on a given object at any given time. Different threads may access the same object at different times. Multiple independent objects may be used from different threads in parallel.

The code described here uses [**getenv**(3)](/getenv/3.md), which is declared to be not multi-thread-safe. This means that the code calling the functions described here must not call [**setenv**(3)](/setenv/3.md) 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 started.

## HISTORY

**sd\_event\_set\_signal\_exit()** was added in version 252.

## SEE ALSO

[**systemd**(1)](/systemd/1.md), [**sd-event**(3)](/sd-event/3.md), [**sd\_event\_new**(3)](/sd_event_new/3.md), [**sd\_event\_add\_signal**(3)](/sd_event_add_signal/3.md)
