---
name: "sd_bus_request_name_async"
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_request_name"
---

# sd\_bus\_request\_name\_async(3)

Request or release a well-known service name on a bus

Part of [sd\_bus\_request\_name(3)](/sd_bus_request_name/3.md).

## NAME

sd\_bus\_request\_name, sd\_bus\_request\_name\_async, sd\_bus\_release\_name, sd\_bus\_release\_name\_async - Request or release a well-known service name on a bus

## SYNOPSIS

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

**typedef int (\*sd\_bus\_message\_handler\_t)(sd\_bus\_message \****m***, void \****userdata***, sd\_bus\_error \****ret\_error***);**

**int sd\_bus\_request\_name(sd\_bus \****bus***, const char \****name***, uint64\_t** *flags***);**

**int sd\_bus\_request\_name\_async(sd\_bus \****bus***, sd\_bus\_slot \*\****slot***, const char \****name***, uint64\_t** *flags***, sd\_bus\_message\_handler\_t** *callback***, void \****userdata***);**

**int sd\_bus\_release\_name(sd\_bus \****bus***, const char \****name***);**

**int sd\_bus\_release\_name\_async(sd\_bus \****bus***, sd\_bus\_slot \*\****slot***, const char \****name***, sd\_bus\_message\_handler\_t** *callback***, void \****userdata***);**

## DESCRIPTION

**sd\_bus\_request\_name()** requests a well-known service name on a bus. It takes a bus connection, a valid bus name, and a flags parameter. The flags parameter is a combination of zero or more of the following flags:

**SD\_BUS\_NAME\_ALLOW\_REPLACEMENT**

After acquiring the name successfully, permit other peers to take over the name when they try to acquire it with the **SD\_BUS\_NAME\_REPLACE\_EXISTING** flag set. If **SD\_BUS\_NAME\_ALLOW\_REPLACEMENT** is not set on the original request, such a request by other peers will be denied.

Added in version 209.

**SD\_BUS\_NAME\_REPLACE\_EXISTING**

Take over the name if it was already acquired by another peer, and that other peer has permitted takeover by setting **SD\_BUS\_NAME\_ALLOW\_REPLACEMENT** while acquiring it.

Added in version 209.

**SD\_BUS\_NAME\_QUEUE**

Queue the acquisition of the name when the name is already taken.

Added in version 209.

**sd\_bus\_request\_name()** operates in a synchronous fashion: a message requesting the name is sent to the bus broker, and the call waits until the broker responds.

**sd\_bus\_request\_name\_async()** is an asynchronous version of **sd\_bus\_request\_name()**. Instead of waiting for the request to complete, the request message is enqueued. The specified *callback* will be called when the broker's response is received. If the parameter is specified as **NULL** a default implementation is used instead which will terminate the connection when the name cannot be acquired. The function returns a slot object in its *slot* parameter — if it is passed as non-**NULL** — which may be used as a reference to the name request operation. Use [**sd\_bus\_slot\_unref**(3)](/sd_bus_slot_unref/3.md) to destroy this reference. Note that destroying the reference will not unregister the name, but simply ensure the specified callback is no longer called.

**sd\_bus\_release\_name()** releases an acquired well-known name. It takes a bus connection and a valid bus name as parameters. This function operates synchronously, sending a release request message to the bus broker and waiting for it to reply.

**sd\_bus\_release\_name\_async()** is an asynchronous version of **sd\_bus\_release\_name()**. The specified *callback* function is called when the name has been released successfully. If specified as **NULL** a generic implementation is used that ignores the result of the operation. As above, the *slot* (if non-**NULL**) is set to an object that may be used to reference the operation.

These functions are supported only on bus connections, i.e. connections to a bus broker and not on direct connections.

## RETURN VALUE

On success, these calls return 0 or a positive integer. On failure, these calls return a negative errno-style error code.

If **SD\_BUS\_NAME\_QUEUE** is specified, **sd\_bus\_request\_name()** will return 0 when the name is already taken by another peer and the client has been added to the queue for the name. In that case, the caller can subscribe to "NameOwnerChanged" signals to be notified when the name is successfully acquired. **sd\_bus\_request\_name()** returns \> 0 when the name has immediately been acquired successfully.

### Errors

Returned errors may indicate the following problems:

**-EALREADY**

The caller already is the owner of the specified name.

**-EEXIST**

The name has already been acquired by a different peer, and SD\_BUS\_NAME\_REPLACE\_EXISTING was not specified or the other peer did not specify SD\_BUS\_NAME\_ALLOW\_REPLACEMENT while acquiring the name.

**-ESRCH**

It was attempted to release a name that is currently not registered on the bus.

**-EADDRINUSE**

It was attempted to release a name that is owned by a different peer on the bus.

**-EINVAL**

A specified parameter is invalid. This is also generated when the requested name is a special service name reserved by the D-Bus specification, or when the operation is requested on a connection that does not refer to a bus.

**-ENOTCONN**

The bus connection has been disconnected.

**-ECHILD**

The bus connection has been created in a different process than the current one.

## 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\_request\_name()** and **sd\_bus\_release\_name()** were added in version 209.

**sd\_bus\_request\_name\_async()** and **sd\_bus\_release\_name\_async()** were added in version 237.

## SEE ALSO

[**systemd**(1)](/systemd/1.md), [**sd-bus**(3)](/sd-bus/3.md), [**sd\_bus\_new**(3)](/sd_bus_new/3.md), [**sd\_bus\_slot\_unref**(3)](/sd_bus_slot_unref/3.md)
