SD_BUS_SLOT_REF(3)
π
SD_BUS_SLOT_REF(3) β aka sd_bus_slot_ref, sd_bus_slot_unref, sd_bus_slot_unrefp β¨
okay so bestie, today's main character is the <systemd/sd-bus.h> bus slot refcount trio π no cap, this one's short and sweet, so let's go π«Ά
πΈ NAME πΈ
sd_bus_slot_ref, sd_bus_slot_unref, sd_bus_slot_unrefp β literally just creating and destroying references to a bus slot object β¨ it's giving "refcount era" and honestly? iconic π
π SYNOPSIS π
#include <systemd/sd-bus.h>
sd_bus_slot *sd_bus_slot_ref(sd_bus_slot *slot);
sd_bus_slot *sd_bus_slot_unref(sd_bus_slot *slot);
void sd_bus_slot_unrefp(sd_bus_slot **slotp);
three functions, one vibe π¦
π DESCRIPTION π
sd_bus_slot_ref() bumps the internal reference counter of slot up by one. increment, bestie, that's it, that's the whole job π
sd_bus_slot_unref() drops the internal reference counter of slot by one. and here's the dramatic part π once that reference count has dropped to zero, the slot object is destroyed and cannot be used anymore β so any further calls to sd_bus_slot_ref() or sd_bus_slot_unref() are illegal. like, off-limits. do not. it's so over at that point π
okay real talk, that last bit is a hard warning β after the refcount hits zero the object is gone for good, and touching it again is undefined-behavior territory. no take-backsies π
sd_bus_slot_unrefp() is basically sd_bus_slot_unref()'s cousin who takes a pointer to a pointer to an sd_bus_slot object instead. this one is lowkey the cleanup-attribute bestie β it pairs perfectly with GCC's and LLVM's Clean-up Variable Attribute[1] π₯ (peep sd_bus_new(3) if you want an actual example of how to use the cleanup attribute, it's right there for you π).
aaaaand the NULL handling rules, because of course π β sd_bus_slot_ref() and sd_bus_slot_unref() execute no operation if the passed-in bus object address is NULL. meanwhile sd_bus_slot_unrefp() will first dereference its argument, which must not be NULL, and then execute no operation if that thing is NULL. two-step vibe check, iykyk π«
β RETURN VALUE β
sd_bus_slot_ref()β always returns the argument. always. it's loyal like that π«Άsd_bus_slot_unref()β always returnsNULL. no notes π
π¦ 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 πΈ
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 may be used from different threads in parallel β¨ (so like, share the object on a schedule, not simultaneously, bestie π)
β οΈ caveat time: the code described here usesgetenv(3), which is declared to be not multi-thread-safe. this means any code calling the functions described here must not callsetenv(3)from a parallel thread. the recommendation? only do calls tosetenv()from an early phase of the program, when no other threads have been started. do it before the group chat gets loud π£
π HISTORY π
sd_bus_slot_ref(), sd_bus_slot_unref(), and sd_bus_slot_unrefp() were added in version 240. vintage but still slaying π
π SEE ALSO π
systemd(1), sd-bus(3), sd_bus_new(3), sd_bus_message_new(3), sd_bus_call_method_async(3) β go read them, they're literally right there π
π NOTES (the footnote one) π
- Clean-up Variable Attribute β https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html
and that's the whole page, bestie β¨ this little gem is from systemd 261.3 β mwah, go refcount responsibly πππ¦
π¦ 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