---
name: "sd_event_source_set_enabled"
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_source_set_enabled"
---

# sd\_event\_source\_set\_enabled(3)

Enable or disable event sources

## NAME

sd\_event\_source\_set\_enabled, sd\_event\_source\_get\_enabled, SD\_EVENT\_ON, SD\_EVENT\_OFF, SD\_EVENT\_ONESHOT - Enable or disable event sources

## SYNOPSIS

```
#include <systemd/sd-event.h>
```

```
enum {
        SD_EVENT_OFF = 0,
        SD_EVENT_ON = 1,
        SD_EVENT_ONESHOT = -1,
};
```

**int sd\_event\_source\_set\_enabled(sd\_event\_source \****source***, int** *enabled***);**

**int sd\_event\_source\_get\_enabled(sd\_event\_source \****source***, int \****ret***);**

## DESCRIPTION

**sd\_event\_source\_set\_enabled()** may be used to enable or disable the event source object specified as *source*. The *enabled* parameter takes one of **SD\_EVENT\_ON** (to enable), **SD\_EVENT\_OFF** (to disable) or **SD\_EVENT\_ONESHOT**. If invoked with **SD\_EVENT\_ONESHOT** the event source will be enabled but automatically reset to **SD\_EVENT\_OFF** after one dispatch. For **SD\_EVENT\_OFF**, the event source *source* may be **NULL**, in which case the function does nothing. Otherwise, *source* must be a valid pointer to an sd\_event\_source object.

Event sources that are disabled will not result in event loop wakeups and will not be dispatched, until they are enabled again.

**sd\_event\_source\_get\_enabled()** may be used to query whether the event source object *source* is currently enabled or not. If both the *source* and the output parameter *ret* are **NULL**, this function returns false. Otherwise, *source* must be a valid pointer to an sd\_event\_source object. If the output parameter *ret* is not **NULL**, it is set to the enablement state (one of **SD\_EVENT\_ON**, **SD\_EVENT\_OFF**, **SD\_EVENT\_ONESHOT**). The function also returns true if the event source is not disabled.

Event source objects are enabled when they are first created with calls such as [**sd\_event\_add\_io**(3)](/sd_event_add_io/3.md), [**sd\_event\_add\_time**(3)](/sd_event_add_time/3.md). However, depending on the event source type they are enabled continuously (**SD\_EVENT\_ON**) or only for a single invocation of the event source handler (**SD\_EVENT\_ONESHOT**). For details see the respective manual pages.

As event source objects stay active and may be dispatched as long as there is at least one reference to them, in many cases it is a good idea to combine a call to [**sd\_event\_source\_unref**(3)](/sd_event_source_unref/3.md) with a prior call to **sd\_event\_source\_set\_enabled()** with **SD\_EVENT\_OFF**, to ensure the event source is not dispatched again until all other remaining references are dropped.

## RETURN VALUE

On success, **sd\_event\_source\_set\_enabled()** returns a non-negative integer. **sd\_event\_source\_get\_enabled()** returns zero if the source is disabled (**SD\_EVENT\_OFF**) and a positive integer otherwise. On failure, they return a negative errno-style error code.

### Errors

Returned errors may indicate the following problems:

**-EINVAL**

*source* is not a valid pointer to an sd\_event\_source object.

**-ENOMEM**

Not enough memory.

**-ECHILD**

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

## 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\_source\_set\_enabled()** and **sd\_event\_source\_get\_enabled()** were added in version 229.

## SEE ALSO

[**sd-event**(3)](/sd-event/3.md), [**sd\_event\_add\_io**(3)](/sd_event_add_io/3.md), [**sd\_event\_add\_time**(3)](/sd_event_add_time/3.md), [**sd\_event\_add\_signal**(3)](/sd_event_add_signal/3.md), [**sd\_event\_add\_child**(3)](/sd_event_add_child/3.md), [**sd\_event\_add\_inotify**(3)](/sd_event_add_inotify/3.md), [**sd\_event\_add\_defer**(3)](/sd_event_add_defer/3.md), [**sd\_event\_source\_unref**(3)](/sd_event_source_unref/3.md), [**sd\_event\_source\_set\_ratelimit**(3)](/sd_event_source_set_ratelimit/3.md)
