SD_BUS_WAIT(3)
π NAME π
bestie, welcome to the SD_BUS_WAIT(3) page β the manual name is sd_bus_wait, and this function is here to wait for I/O on a bus connection. iconic little helper behavior, ngl.
β¨ SYNOPSIS β¨
#include <systemd/sd-bus.h>
int sd_bus_wait(sd_bus *bus, uint64_t timeout_usec);
π¦ DESCRIPTION π¦
sd_bus_wait() synchronously waits for I/O on the specified bus connection object. lowkey its whole job. This function is supposed to be called whenever sd_bus_process(3) returns zero, indicating that no work is pending on the connection. so when sd_bus_process(3) says βnah, nothing rn,β this is your girl.
Internally, this call invokes ppoll(2), to wait for I/O on the bus connection. If the timeout_usec parameter is specified, the call will block at most for the specified amount of time in ΞΌs. Pass UINT64_MAX to permit it to sleep indefinitely. yes bestie, UINT64_MAX is the βgo to sleep foreverβ pass π€
After each invocation of sd_bus_wait() the sd_bus_process() call should be invoked in order to process any now pending I/O work. so the vibe is: wait, then process. wait, then process. main character loop energy.
Note thatsd_bus_wait()is suitable only for simple programs as it does not permit waiting for other I/O events. For more complex programs either connect the bus connection object to an external event loop usingsd_bus_get_fd(3)or to ansd-event(3)event loop usingsd_bus_attach_event(3).
so if your program is simple, slay. if it's complex, don't make this function carry the whole event loop on its back β hook it up to an external event loop with sd_bus_get_fd(3) or to an sd-event(3) event loop with sd_bus_attach_event(3). periodt.
π RETURN VALUE π
If any I/O was seen, a positive value is returned, zero otherwise. If an error occurs, a negative errno-style error code is returned. no cap.
π Errors
Returned errors may indicate the following problems:
-EINVALβ An invalid bus object was passed. bestie, that bus object is not giving valid.-ECHILDβ The bus connection was allocated in a parent process and is being reused in a child process afterfork(). fork drama, honestly.-ENOTCONNβ The bus connection has been terminated already. it's gone, babes π
π 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. yes, link it up properly.
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. so: not a free-for-all on one object at the same time, but different objects can absolutely do their own thing in parallel. love that for them.
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, do your setenv() era before the threads wake up.
π HISTORY π
sd_bus_wait() was added in version 240. vintage-ish but still cute.
π SEE ALSO π
and that's the page, bestie π«Ά source/version vibes: systemd 261.3; the footer also gave SD_BUS_WAIT(3), and since the date field wasn't listed there, I'm not inventing one β mwah π
β¨
π¦ 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