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, use sd_bus_set_connected_signal(3) and install a match for the Connected() signal on the "org.freedesktop.DBus.Local" interface. to be notified when the connection is torn down again, install a match for the Disconnected() 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 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. 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 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. ⚠️
🚨 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