---
name: "sd_bus_message_send"
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_send"
---

# sd\_bus\_message\_send(3)

Queue a D-Bus message for transfer

Part of [sd\_bus\_send(3)](/sd_bus_send/3.md).

## NAME

sd\_bus\_send, sd\_bus\_send\_to, sd\_bus\_message\_send - Queue a D-Bus message for transfer

## SYNOPSIS

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

**int sd\_bus\_send(sd\_bus \****bus***, sd\_bus\_message \****m***, uint64\_t \****cookie***);**

**int sd\_bus\_send\_to(sd\_bus \****bus***, sd\_bus\_message \****m***, const char \****destination***, uint64\_t \****cookie***);**

**int sd\_bus\_message\_send(sd\_bus\_message \****m***);**

## DESCRIPTION

**sd\_bus\_send()** queues the bus message object *m* for transfer. If *bus* is **NULL**, the bus that *m* is attached to is used. *bus* only needs to be set when the message is sent to a different bus than the one it is attached to, for example when forwarding messages. If the output parameter *cookie* is not **NULL**, it is set to the message identifier. This value can later be used to match incoming replies to their corresponding messages. If *cookie* is set to **NULL** and the message is not sealed, **sd\_bus\_send()** assumes the message *m* does not expect a reply and adds the necessary headers to indicate this.

Note that in most scenarios, **sd\_bus\_send()** should not be called directly. Instead, use higher level functions such as [**sd\_bus\_call\_method**(3)](/sd_bus_call_method/3.md) and [**sd\_bus\_reply\_method\_return**(3)](/sd_bus_reply_method_return/3.md) which call **sd\_bus\_send()** internally.

**sd\_bus\_send\_to()** is a shorthand for sending a message to a specific destination. It's main use case is to simplify sending unicast signal messages (signals that only have a single receiver). It's behavior is similar to calling [**sd\_bus\_message\_set\_destination**(3)](/sd_bus_message_set_destination/3.md) followed by calling **sd\_bus\_send()**.

**sd\_bus\_send()**/**sd\_bus\_send\_to()** will write the message directly to the underlying transport (e.g. kernel socket buffer) if possible. If the connection is not set up fully yet the message is queued locally. If the transport buffers are congested any unwritten message data is queued locally, too. If the connection has been closed or is currently being closed the call fails. [**sd\_bus\_process**(3)](/sd_bus_process/3.md) should be invoked to write out any queued message data to the transport.

**sd\_bus\_message\_send()** is the same as **sd\_bus\_send()** but without the first and last argument. **sd\_bus\_message\_send(m)** is equivalent to **sd\_bus\_send(sd\_bus\_message\_get\_bus(m), m, NULL)**.

## RETURN VALUE

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

### Errors

Returned errors may indicate the following problems:

**-EINVAL**

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

Added in version 246.

**-EOPNOTSUPP**

The bus connection does not support sending file descriptors.

Added in version 246.

**-ECHILD**

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

Added in version 246.

**-ENOBUFS**

The bus connection's write queue is full.

Added in version 246.

**-ENOTCONN**

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

Added in version 246.

**-ECONNRESET**

The bus connection was closed while waiting for the response.

Added in version 246.

**-ENOMEM**

Memory allocation failed.

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\_send()** and **sd\_bus\_send\_to()** were added in version 246.

## 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\_message\_set\_destination**(3)](/sd_bus_message_set_destination/3.md), [**sd\_bus\_reply\_method\_return**(3)](/sd_bus_reply_method_return/3.md), [**sd\_bus\_process**(3)](/sd_bus_process/3.md)
