---
name: "sd_bus_call"
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_call"
---

# sd\_bus\_call(3)

Invoke a D-Bus method call

## NAME

sd\_bus\_call, sd\_bus\_call\_async - Invoke a D-Bus method call

## 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\_call(sd\_bus \****bus***, sd\_bus\_message \****m***, uint64\_t** *usec***, sd\_bus\_error \****ret\_error***, sd\_bus\_message \*\****reply***);**

**int sd\_bus\_call\_async(sd\_bus \****bus***, sd\_bus\_slot \*\****slot***, sd\_bus\_message \****m***, sd\_bus\_message\_handler\_t** *callback***, void \****userdata***, uint64\_t** *usec***);**

## DESCRIPTION

**sd\_bus\_call()** takes a complete bus message object and calls the corresponding D-Bus method. On success, the response is stored in *reply*. *usec* indicates the timeout in microseconds. If *ret\_error* is not **NULL** and **sd\_bus\_call()** fails (either because of an internal error or because it received a D-Bus error reply), *ret\_error* is initialized to an instance of sd\_bus\_error describing the error.

**sd\_bus\_call\_async()** is like **sd\_bus\_call()** but works asynchronously. The *callback* indicates the function to call when the response arrives. The *userdata* pointer will be passed to the callback function, and may be chosen freely by the caller. If *slot* is not **NULL** and **sd\_bus\_call\_async()** succeeds, *slot* is set to a slot object which can be used to cancel the method call at a later time using [**sd\_bus\_slot\_unref**(3)](/sd_bus_slot_unref/3.md). If *slot* is **NULL**, the lifetime of the method call is bound to the lifetime of the bus object itself, and it cannot be cancelled independently. See [**sd\_bus\_slot\_set\_floating**(3)](/sd_bus_slot_set_floating/3.md) for details. *callback* is called when a reply arrives with the reply, *userdata* and an sd\_bus\_error output parameter as its arguments. Unlike **sd\_bus\_call()**, the sd\_bus\_error output parameter passed to the callback will be empty. To determine whether the method call succeeded, use [**sd\_bus\_message\_is\_method\_error**(3)](/sd_bus_message_is_method_error/3.md) on the reply message passed to the callback instead. If the callback returns zero and the sd\_bus\_error output parameter is still empty when the callback finishes, other handlers registered with functions such as [**sd\_bus\_add\_filter**(3)](/sd_bus_add_filter/3.md) or [**sd\_bus\_add\_match**(3)](/sd_bus_add_match/3.md) are given a chance to process the message. If the callback returns a non-zero value or the sd\_bus\_error output parameter is not empty when the callback finishes, no further processing of the message is done. Generally, you want to return zero from the callback to give other registered handlers a chance to process the reply as well. (Note that the sd\_bus\_error parameter is an output parameter of the callback function, not an input parameter; it can be used to propagate errors from the callback handler, it will not receive any error that was received as method reply.)

The message *m* passed to the callback is only borrowed, that is, the callback should not call [**sd\_bus\_message\_unref**(3)](/sd_bus_message_unref/3.md) on it. If the callback wants to hold on to the message beyond the lifetime of the callback, it needs to call [**sd\_bus\_message\_ref**(3)](/sd_bus_message_ref/3.md) to create a new reference.

If *usec* is zero, the default D-Bus method call timeout is used. See [**sd\_bus\_get\_method\_call\_timeout**(3)](/sd_bus_get_method_call_timeout/3.md).

## RETURN VALUE

On success, these functions return a non-negative integer. On failure, they return a negative errno-style error code.

### Errors

When **sd\_bus\_call()** internally receives a D-Bus error reply, it will set *ret\_error* if it is not **NULL**, and will return a negative value mapped from the error reply, see [**sd\_bus\_error\_get\_errno**(3)](/sd_bus_error_get_errno/3.md).

Returned errors may indicate the following problems:

**-EINVAL**

The input parameter *m* is **NULL**.

The input parameter *m* is not a D-Bus method call. To create a new D-Bus method call, use [**sd\_bus\_message\_new\_method\_call**(3)](/sd_bus_message_new_method_call/3.md).

The input parameter *m* has the **BUS\_MESSAGE\_NO\_REPLY\_EXPECTED** flag set.

The input parameter *error* is non-**NULL** but was not set to **SD\_BUS\_ERROR\_NULL**.

**-ECHILD**

The bus connection was allocated in a parent process and is being reused in a child process after **fork()**.

**-ENOTCONN**

The input parameter *bus* is **NULL** or the bus is not connected.

**-ECONNRESET**

The bus connection was closed while waiting for the response.

**-ETIMEDOUT**

A response was not received within the given timeout.

**-ELOOP**

The message *m* is addressed to its own client.

**-ENOMEM**

Memory allocation failed.

## 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\_call()** and **sd\_bus\_call\_async()** were added in version 221.

## SEE ALSO

[**systemd**(1)](/systemd/1.md), [**sd-bus**(3)](/sd-bus/3.md), [**sd\_bus\_call\_method**(3)](/sd_bus_call_method/3.md), [**sd\_bus\_call\_method\_async**(3)](/sd_bus_call_method_async/3.md), [**sd\_bus\_message\_new\_method\_call**(3)](/sd_bus_message_new_method_call/3.md), [**sd\_bus\_message\_append**(3)](/sd_bus_message_append/3.md), [**sd\_bus\_error**(3)](/sd_bus_error/3.md)
