SD_BUS_S...ISCONNECT(3)

πŸ’… SD_BUS_S...ISCONNECT(3) β€” sd_bus_set_exit_on_disconnect πŸ’…

okay bestie, welcome to the manual page for sd_bus_set_exit_on_disconnect (the page header calls it SD_BUS_S...ISCONNECT(3)), and it’s all about controlling what happens when your bus object disconnects. no cap. ✨


🌸 NAME 🌸

sd_bus_set_exit_on_disconnect, sd_bus_get_exit_on_disconnect β€” control the exit behavior when the bus object disconnects. that’s the whole plot, and honestly it’s giving β€œtiny switch, big consequences.” πŸ’…


✨ SYNOPSIS ✨

#include <systemd/sd-bus.h>

int sd_bus_set_exit_on_disconnect(sd_bus *bus, int b);

int sd_bus_get_exit_on_disconnect(sd_bus *bus);

πŸ¦‹ DESCRIPTION πŸ¦‹

so sd_bus_set_exit_on_disconnect() may be used to configure the exit behavior when the given bus object disconnects. yes bestie, it’s literally the β€œwhat do we do when this thing bails?” button. 😭

if b is zero, no special logic is executed when the bus object disconnects. it’s just… nothing. calm. no drama. πŸŽ€

if b is non-zero, the behavior on disconnect depends on whether the bus object is attached to an event loop or not. this is the part where you gotta know your setup, fr fr. ✨

the exit code passed to sd_event_exit() and exit() is EXIT_FAILURE. periodt. πŸ”₯

bestie, if the bus object has already disconnected when enabling the exit behavior, the exit behavior is executed immediately β€” not later, not after a vibe check. 😭

by default, the exit behavior is disabled. so if you want this energy, you gotta turn it on yourself. πŸ’…

sd_bus_get_exit_on_disconnect() returns whether the exit on disconnect behavior is enabled for the given bus object. it’s the little β€œis this thing on?” check. 🫢


πŸ’– RETURN VALUE πŸ’–

  • on success, sd_bus_set_exit_on_disconnect() returns a non-negative integer. slay. ✨
  • on failure, it returns a negative errno-style error code. not slay, but useful. 😭

sd_bus_get_exit_on_disconnect() returns a positive integer if the exit on disconnect behavior is enabled. otherwise, it returns zero. simple as that. πŸ’…

😭 Errors 😭

returned errors may indicate the following problems:

  • -EINVAL β€” a required parameter was NULL. Added in version 246. bestie, someone forgot to pass the thing. πŸ™ˆ
  • -ENOPKG β€” the bus object could not be resolved. Added in version 246. it’s giving β€œcan’t find the main character.” πŸ’€
  • -ECHILD β€” the bus connection was created in a different process, library or module instance. Added in version 246. wrong family, wrong house. 🫠

πŸŽ€ 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. iconic build-system behavior, honestly. ✨

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 the object responsibly, bestie. 🫢

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. πŸ”₯ no chaotic parallel setenv(3) energy. keep it early, keep it cute. πŸ’…

🌈 HISTORY 🌈

sd_bus_set_exit_on_disconnect() and sd_bus_get_exit_on_disconnect() were added in version 246. a little vintage, a little iconic. πŸŽ€


⭐ SEE ALSO ⭐


πŸ’– cute sign-off: this page is from systemd 261.3 β€” and the original footer’s date slot is not filled in on this copy, so no date to report, bestie. πŸ’–

πŸ“¦ where this page comes from