SD_BUS_S...CALLBACK(3)
π SD_BUS_S...CALLBACK β the resource-cleanup callback page π
okay so this is the sd_bus_slot_set_destroy_callback manpage from sd_bus_slot_set_destroy_callback, bestie β it's a <italic>systemd</italic> one, and it's all about defining the callback function for resource cleanup β¨. yes it's as iconic as it sounds, stay with me.
πΈ NAME πΈ
sd_bus_slot_set_destroy_callback, sd_bus_slot_get_destroy_callback, sd_bus_track_set_destroy_callback, sd_bus_track_get_destroy_callback, and sd_bus_destroy_t β literally the whole squad whose job is defining the callback function for resource cleanup π§Ήπ
β¨ SYNOPSIS β¨
#include <systemd/sd-bus.h>
typedef int (*sd_bus_destroy_t)(void *userdata);
int sd_bus_slot_set_destroy_callback(sd_bus_slot *slot,
sd_bus_destroy_t callback);
int sd_bus_slot_get_destroy_callback(sd_bus_slot *slot,
sd_bus_destroy_t *callback);
int sd_bus_track_set_destroy_callback(sd_bus_track *track,
sd_bus_destroy_t callback);
int sd_bus_track_get_destroy_callback(sd_bus_track *track,
sd_bus_destroy_t *callback);
look at that type definition, she's serving main character energy π₯ sd_bus_destroy_t takes a void *userdata and returns an int, periodt.
π¦ DESCRIPTION π¦
okay so sd_bus_slot_set_destroy_callback() sets callback as the callback function to be called right before the bus slot object slot is deallocated π. the userdata pointer from the slot object gets passed in as the userdata parameter β cute, right? that pointer can be set either by an argument to the constructor functions (go peek at sd_bus_add_match(3) π) or directly (that's sd_bus_slot_set_userdata(3)). and ngl this callback function is called even if userdata is NULL β no skipping, no excuses π.
β οΈ ok this part is important bestie, lowkey the whole vibe check of the page: this callback is invoked at a time where the bus slot object itself is already invalidated. so executing operations on it or taking new references to the bus slot object is not permissible β like, do NOT. it's giving "the party's over, don't text" π
sd_bus_slot_get_destroy_callback() hands you back the current callback for slot in the callback parameter π«Ά.
sd_bus_track_set_destroy_callback() and sd_bus_track_get_destroy_callback() provide equivalent functionality for the userdata pointer associated with bus peer tracking objects π«. wanna know more about bus peer tracking objects? sd_bus_track_new(3), slay.
π RETURN VALUE π
On success, sd_bus_slot_set_destroy_callback() and sd_bus_track_set_destroy_callback() return 0 or a positive integer β. On failure, they return a negative errno-style error code π.
sd_bus_slot_get_destroy_callback() and sd_bus_track_get_destroy_callback() return positive if the destroy callback function is set, and 0 if not π
. On failure, they return a negative errno-style error code.
π Errors
returned errors may indicate the following problems, iykyk:
-EINVALβ theslotortrackparameter isNULLπ (yeah, you gotta actually give her something to work with)
π 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 β that one's fine, go off π
β οΈ the code described here usesgetenv(3), which is declared to be not multi-thread-safe. this means that the code calling the functions described here must not callsetenv(3)from a parallel thread. the recommendation is to only do calls tosetenv()from an early phase of the program when no other threads have been started π β like, handle that business before the group chat gets going, fr fr.
π HISTORY π
sd_bus_destroy_t(), sd_bus_slot_set_destroy_callback(), sd_bus_slot_get_destroy_callback(), sd_bus_track_set_destroy_callback(), and sd_bus_track_get_destroy_callback() were added in version 239 β (a classic, honestly, she aged beautifully)
π SEE ALSO π
systemd(1), sd-bus(3), sd_bus_slot_set_floating(3), sd_bus_add_match(3), sd_bus_track_new(3), sd_bus_slot_set_userdata(3), sd_bus_track_set_userdata(3) π¦
okay bestie that's the whole page, no gatekeeping, no missing flags π this little love letter comes to you from systemd 261.3, dated SD_BUS_S...CALLBACK(3) β go forth and clean up your resources responsibly, 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