SD_BUS_SET_SERVER(3)

πŸ’– sd_bus_set_server(3) β€” Configure connection mode for a bus object πŸ’–

okay bestie, welcome to the SD_BUS_SET_SERVER(3) manual page β€” the one all about configuring connection mode for a bus object. It's giving very β€œI know my way around D-Bus” energy, and we're gonna get through every single detail together. 🫢

✨ 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 β€” all of these are here to configure connection mode for a bus object. Periodt. πŸ’…

🌸 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 πŸ¦‹

Here's the vibe check on what each function is doing:

  • sd_bus_set_server() β€” configures the bus object as a server for direct D-Bus connections. The b argument enables/disables server mode. If b is zero, server mode is disabled; otherwise, 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. The 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) can be used to generate a random id instead. πŸ’…
  • sd_bus_is_server() β€” returns whether server mode is enabled for the given bus object. Simple, iconic, no drama.
  • sd_bus_get_bus_id() β€” stores the D-Bus server id in id. That id is either the one configured using sd_bus_set_server() (for server bus objects) or the one received during D-Bus authentication (for client bus objects). πŸŽ€
  • sd_bus_set_bus_client() β€” configures the bus object as a D-Bus daemon client. The b argument enables/disables client mode. If b is zero, client mode is disabled and the bus object should connect directly to a D-Bus server. Otherwise, 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) family of functions or any of the functions in the sd_bus_default(3) 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) followed by sd_bus_start(3), 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. lowkey important, bestie.
  • sd_bus_is_bus_client() β€” returns whether client mode is enabled/disabled for the given bus object.
  • sd_bus_set_monitor() β€” configures the bus object as a D-Bus monitor object. The b argument enables/disables monitor mode. If b is zero, monitor mode is disabled. If b is non-zero, monitor mode is enabled. When 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 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) 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), which is declared to be not multi-thread-safe. This means that the code calling the functions described here must not call setenv(3) 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. fr fr, don't be messy with threads here.

🌈 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 πŸ‘‘

πŸ“ NOTES πŸ“

  1. The D-Bus specification β€” https://dbus.freedesktop.org/doc/dbus-specification.html#bus-messages-become-monitor

That's the whole page, bestie β€” footer vibes are systemd 261.3 and SD_BUS_SET_SERVER(3), and there's no date printed on this page. πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from