SD_BUS_START(3)
π
SD_BUS_START(3) β like, the sd_bus_start page, bestie β¨
okay so real talk, this is page SD_BUS_START(3) from the sd_bus_start manual, aka the glow-up-your-bus-connection page. it's a systemd one. let's get into it π
πΈ NAME πΈ
sd_bus_start β bestie, this is the call that actually kicks off a bus connection to the D-bus broker daemon. it's giving "press start, but for IPC" π¦
β¨ SYNOPSIS β¨
#include <systemd/sd-bus.h>
int sd_bus_start(sd_bus *bus);
that's it. one function, one pointer, no cap π
π DESCRIPTION π
so sd_bus_start() takes an existing bus connection object and connects it to the D-Bus broker daemon β usually dbus-daemon(1) or dbus-broker(1), iykyk.
here's the thing tho π: the mechanism it's gonna use for the connection has to be configured before you call sd_bus_start(). like, you gotta set that up first, using one of:
then sd_bus_start() will open the connection socket or spawn the executable, as needed, and asynchronously fire off an org.freedesktop.DBus.Hello() call π₯. the answer to that Hello call gets processed later, from sd_bus_process(3) β so don't be out here expecting it immediately, it's an async vibe.
and if opening the connection fails, or queuing up that asynchronous call fails? the connection gets closed with sd_bus_close(3). sad but clean π
ngl, in most cases it's better to usesd_bus_default_user(3),sd_bus_default_system(3), or the related calls instead of going low-level withsd_bus_new()andsd_bus_start(). the higher-level functions don't just allocate a bus object β they also start the connection to a well-known bus, all in one single function call. main character energy, fr fr π
π«Ά RETURN VALUE π«Ά
on success, this function returns a non-negative integer β¨. on failure, it returns a negative errno-style error code. periodt.
π Errors π
-EINVALβ the input parameter bus isNULL. (rude, but okay.)- Added in version 246.
-ENOPKGβ the bus object bus could not be resolved. π- Added in version 246.
-EPERMβ the input parameter bus is in a wrong state. heads up:sd_bus_start()may only be called once on a newly-created bus object. one and done, bestie π- Added in version 246.
-ECHILDβ the bus object bus was created in a different process. like, it's not yours, it's not from your process, so no π«- Added in version 246.
plus, other connection-related errors may be returned too β go peek at sd_bus_send(3) for those π
π§ NOTES π§
the functions described here are available as a shared library, which you can compile against and link to with the libsystemd pkg-config(1) file. slay π
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. and multiple independent objects can absolutely be used from different threads in parallel β parallel besties, no drama π
β οΈ okay important one: the code described here usesgetenv(3), which is declared to be not multi-thread-safe. meaning: code calling the functions described here must not callsetenv(3)from a parallel thread. the recommendation is to only dosetenv()calls from an early phase of the program, when no other threads have been started yet. do it early or don't do it π
β HISTORY β
sd_bus_start() was added in version 246. iconic since day one, fr π
πΈ SEE ALSO πΈ
systemd(1), sd-bus(3), sd_bus_default(3), sd_bus_call_async(3) β go read those next, bestie, they're all connected π¦
mwah π that's the whole page β brought to you by systemd 261.3, the SD_BUS_START(3) girlies, and me, your local Unix-literate group chat π«Άβ¨
π¦ where this page comes from
- ubuntu stonking: libsystemd-dev 261.3-0ubuntu3 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms