---
name: "sd_bus_get_exit_on_disconnect"
section: "3"
platform: "linux"
package: "libsystemd-dev"
version: "257.13-1~deb13u1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/sd_bus_set_exit_on_disconnect"
---

# sd\_bus\_get\_exit\_on\_disconnect(3)

Control the exit behavior when the bus object disconnects

Part of [sd\_bus\_set\_exit\_on\_disconnect(3)](/sd_bus_set_exit_on_disconnect/3.md).

## NAME

sd\_bus\_set\_exit\_on\_disconnect, sd\_bus\_get\_exit\_on\_disconnect - Control the exit behavior when the bus object disconnects

## SYNOPSIS

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

**int sd\_bus\_set\_exit\_on\_disconnect(sd\_bus \****bus***, int** *b***);**

**int sd\_bus\_get\_exit\_on\_disconnect(sd\_bus \****bus***);**

## DESCRIPTION

**sd\_bus\_set\_exit\_on\_disconnect()** may be used to configure the exit behavior when the given bus object disconnects. If *b* is zero, no special logic is executed when the bus object disconnects. If *b* is non-zero, the behavior on disconnect depends on whether the bus object is attached to an event loop or not. If the bus object is attached to an event loop (see [**sd\_bus\_attach\_event**(3)](/sd_bus_attach_event/3.md)), the event loop is closed when the bus object disconnects (as if calling [**sd\_event\_exit**(3)](/sd_event_exit/3.md)). Otherwise, [**exit**(3)](/exit/3.md) is called. The exit code passed to **sd\_event\_exit()** and **exit()** is **EXIT\_FAILURE**. If the bus object has already disconnected when enabling the exit behavior, the exit behavior is executed immediately. By default, the exit behavior is disabled.

**sd\_bus\_get\_exit\_on\_disconnect()** returns whether the exit on disconnect behavior is enabled for the given bus object.

## RETURN VALUE

On success, **sd\_bus\_set\_exit\_on\_disconnect()** returns a non-negative integer. On failure, it returns a negative errno-style error code.

**sd\_bus\_get\_exit\_on\_disconnect()** returns a positive integer if the exit on disconnect behavior is enabled. Otherwise, it returns zero.

### Errors

Returned errors may indicate the following problems:

**-EINVAL**

A required parameter was **NULL**.

Added in version 246.

**-ENOPKG**

The bus object could not be resolved.

Added in version 246.

**-ECHILD**

The bus connection was created in a different process, library or module instance.

Added in version 246.

## 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.

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\_bus\_set\_exit\_on\_disconnect()** and **sd\_bus\_get\_exit\_on\_disconnect()** were added in version 246.

## SEE ALSO

[**systemd**(1)](/systemd/1.md), [**sd-bus**(3)](/sd-bus/3.md), [**sd\_bus\_attach\_event**(3)](/sd_bus_attach_event/3.md), [**sd-event**(3)](/sd-event/3.md), [**sd\_event\_exit**(3)](/sd_event_exit/3.md)
