---
name: "sd_bus_set_server"
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_bus_set_server"
---

# sd\_bus\_set\_server(3)

Configure connection mode for a bus object

## NAME

sd\_bus\_set\_server, sd\_bus\_is\_server, sd\_bus\_get\_bus\_id, sd\_bus\_set\_bus\_client, sd\_bus\_is\_bus\_client, sd\_bus\_set\_monitor, sd\_bus\_is\_monitor - Configure connection mode for a bus object

## SYNOPSIS

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

**int sd\_bus\_set\_server(sd\_bus \****bus***, int** *b***, sd\_id128\_t** *id***);**

**int sd\_bus\_is\_server(sd\_bus \****bus***);**

**int sd\_bus\_get\_bus\_id(sd\_bus \****bus***, sd\_id128\_t \****id***);**

**int sd\_bus\_set\_bus\_client(sd\_bus \****bus***, int** *b***);**

**int sd\_bus\_is\_bus\_client(sd\_bus \****bus***);**

**int sd\_bus\_set\_monitor(sd\_bus \****bus***, int** *b***);**

**int sd\_bus\_is\_monitor(sd\_bus \****bus***);**

## DESCRIPTION

**sd\_bus\_set\_server()** configures the bus object as a server for direct D-Bus connections. *b* enables/disables the server mode. If zero, the server mode is disabled. Otherwise, the server mode is enabled. Configuring a bus object as a server is required to allow establishing direct connections between two peers without going via the D-Bus daemon. *id* must contain a 128-bit integer id for the server. If clients add a guid field to their D-Bus address string, the server id must match this guid or the D-Bus authentication handshake will fail. If no specific id is defined for the server, [**sd\_id128\_randomize**(3)](/sd_id128_randomize/3.md) can be used to generate a random id instead.

**sd\_bus\_is\_server()** returns whether the server mode is enabled for the given bus object.

**sd\_bus\_get\_bus\_id()** stores the D-Bus server id configured using **sd\_bus\_set\_server()** (for server bus objects) or received during D-Bus authentication (for client bus objects) in *id*.

**sd\_bus\_set\_bus\_client()** configures the bus object as a D-Bus daemon client. *b* enables/disables the client mode. If zero, the client mode is disabled and the bus object should connect directly to a D-Bus server. Otherwise, the client mode is enabled and the bus object should connect to a D-Bus daemon. When connecting to an existing bus using any of the functions in the [**sd\_bus\_open**(3)](/sd_bus_open/3.md) family of functions or any of the functions in the [**sd\_bus\_default**(3)](/sd_bus_default/3.md) family of functions, the bus object is automatically configured as a bus client. However, when connecting to a D-Bus daemon by calling [**sd\_bus\_set\_address**(3)](/sd_bus_set_address/3.md) followed by [**sd\_bus\_start**(3)](/sd_bus_start/3.md), the bus object should be manually configured as a bus client using **sd\_bus\_set\_bus\_client()**. By default, a bus object is not configured as a D-Bus daemon client.

**sd\_bus\_is\_bus\_client()** returns whether the client mode is enabled/disabled for the given bus object.

**sd\_bus\_set\_monitor()** configures the bus object as a D-Bus monitor object. *b* enables/disables the monitor mode. If zero, the monitor mode is disabled. If non-zero, the monitor mode is enabled. When the monitor mode is enabled, no messages may be sent via the bus object and it may not expose any objects on the bus. To start monitoring messages, call the **org.freedesktop.DBus.Monitoring.BecomeMonitor** method of the D-Bus daemon and pass a list of matches indicating which messages to intercept. See **The D-Bus specification**\[1\] for more information.

**sd\_bus\_is\_monitor()** returns whether the monitor mode is enabled/disabled for the given bus object.

## RETURN VALUE

On success, **sd\_bus\_set\_server()**, **sd\_bus\_get\_bus\_id()**, **sd\_bus\_set\_bus\_client()** and **sd\_bus\_set\_monitor()** return a non-negative integer. On failure, they return a negative errno-style error code.

**sd\_bus\_is\_server()**, **sd\_bus\_is\_bus\_client()** and **sd\_bus\_is\_monitor()** return a positive integer when the server or client mode is enabled, respectively. Otherwise, they return zero.

### Errors

Returned errors may indicate the following problems:

**-ECHILD**

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

Added in version 246.

**-EPERM**

The bus connection has already been started.

Added in version 246.

**-ENOPKG**

The bus cannot be resolved.

Added in version 246.

**-EINVAL**

A required parameter was **NULL** or *b* was zero and *id* did not equal **SD\_ID128\_NULL**.

Added in version 246.

**-ENOTCONN**

The bus is not connected.

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.

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\_bus\_set\_server()**, **sd\_bus\_is\_server()**, **sd\_bus\_get\_bus\_id()**, **sd\_bus\_set\_bus\_client()**, **sd\_bus\_is\_bus\_client()**, **sd\_bus\_set\_monitor()**, and **sd\_bus\_is\_monitor()** were added in version 246.

## SEE ALSO

[**systemd**(1)](/systemd/1.md), [**sd-bus**(3)](/sd-bus/3.md)

## NOTES

- 1\.

  The D-Bus specification

  https://dbus.freedesktop.org/doc/dbus-specification.html#bus-messages-become-monitor
