SD_BUS_IS_OPEN(3)
β¨ SD_BUS_IS_OPEN(3) β the "is my bus even alive rn" check β¨
okay bestie, so this is a systemd / sd-bus manual page β it's <pink>SD_BUS_IS_OPEN</pink> from the sd_bus_is_open family, and it's genuinely so useful. it's giving "vibe check for your D-Bus connection" π
let's get into it.
π¦ NAME π¦
sd_bus_is_open, sd_bus_is_ready β literally just checking whether your bus connection is open or ready. that's the whole assignment, no cap π
πΈ SYNOPSIS πΈ
#include <systemd/sd-bus.h>
int sd_bus_is_open(sd_bus *bus);
int sd_bus_is_ready(sd_bus *bus);
two little functions, both taking an sd_bus *bus, both handing you back an int. iconic. π
π DESCRIPTION π
okay so first up: sd_bus_is_open() β this one checks whether the bus connection you specified is actually open. and by "open" we mean any of these three moments in its little life:
- it's currently in the process of being established,
- it's already established, or
- it's in the process of being torn down again π
it returns zero when the connection hasn't been started yet β like, sd_bus_start(3) or some equivalent call hasn't been invoked yet, so it's just sitting there β or when it's fully terminated again (for example after sd_bus_close(3)). and it returns positive otherwise. slay.
then we have sd_bus_is_ready() β this is the stricter one, she has standards π. it checks whether the connection is fully established, meaning it:
- completed the connection and authentication phases of the protocol, and
- received the
Hello()method call response, and - is not in the process of being torn down again.
it returns zero outside of this state and positive otherwise. basically, this function returns positive while regular messages can actually be sent or received on the connection β that's the vibe check that matters fr fr π₯
oh and important: the bus argument may be NULL, and if it is, zero is also returned in that case. no crash, no drama, just 0. π«Ά
π§ want notifications bestie? to be notified when the connection is fully established, usesd_bus_set_connected_signal(3)and install a match for theConnected()signal on the"org.freedesktop.DBus.Local"interface. to be notified when the connection is torn down again, install a match for theDisconnected()signal on the"org.freedesktop.DBus.Local"interface. same interface, different signal, both iconic.
β RETURN VALUE β
those functions return 0 if the bus is not in the given state, and a positive integer when it is. and on failure? a negative errno-style error code comes back at you. π
π Errors π
returned errors may indicate the following problems β there's exactly one to know about:
-ECHILDβ the bus connection has been created in a different process, library or module instance. so likeβ¦ it's not yours, bestie. different household. π
π NOTES π
- the functions described here are available as a shared library, which can be compiled against and linked to with the
libsystemdpkg-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. so like, share nicely, take turns, one at a time π
- the code described here uses
getenv(3), which is declared to be not multi-thread-safe. this means the code calling the functions described here must not callsetenv(3)from a parallel thread. it is recommended to only do calls tosetenv()from an early phase of the program when no other threads have been started. β οΈ
π¨ seriously though, that last one is a real caveat β the "not multi-thread-safe" thing is not a joke, it's the actual documented behaviour. don't be calling setenv(3) from a parallel thread while this code is running.
π HISTORY π
sd_bus_is_open()was added in version 221. a classic, honestly.sd_bus_is_ready()was added in version 237. the newer baby sister. β¨
π«Ά SEE ALSO π«Ά
systemd(1), sd-bus(3), sd_bus_start(3), sd_bus_close(3), sd_bus_set_connected_signal(3)
those are your besties, go read them too, iykyk π¦
mwah π that's the whole page β brought to you by systemd 261.3, dated SD_BUS_IS_OPEN(3). go check if your bus is open, bestie, and slay the day πΈβπ
π¦ 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