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 β€” the slot or track parameter is NULL 😭 (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 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. the recommendation is to only do calls to setenv() 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