---
name: "sd_bus_destroy_t"
section: "3"
platform: "linux"
package: "libsystemd-dev"
version: "257.13-1~deb13u1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/sd_bus_slot_set_destroy_callback"
---

# sd\_bus\_destroy\_t(3)

Define the callback function for resource cleanup

Part of [sd\_bus\_slot\_set\_destroy\_callback(3)](/sd_bus_slot_set_destroy_callback/3.md).

## 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, sd\_bus\_destroy\_t - Define 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***);**

## DESCRIPTION

**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 will be passed as the *userdata* parameter. This pointer can be set by an argument to the constructor functions, see [**sd\_bus\_add\_match**(3)](/sd_bus_add_match/3.md), or directly, see [**sd\_bus\_slot\_set\_userdata**(3)](/sd_bus_slot_set_userdata/3.md). This callback function is called even if *userdata* is **NULL**. Note that this callback is invoked at a time where the bus slot object itself is already invalidated, and executing operations or taking new references to the bus slot object is not permissible.

**sd\_bus\_slot\_get\_destroy\_callback()** returns 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. For details about bus peer tracking objects, see [**sd\_bus\_track\_new**(3)](/sd_bus_track_new/3.md).

## 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, 0 if not. On failure, they return a negative errno-style error code.

### Errors

Returned errors may indicate the following problems:

**-EINVAL**

The *slot* or *track* parameter is **NULL**.

## NOTES

Functions described here are available as a shared library, which can be compiled against and linked to with the **libsystemd** [**pkg-config**(1)](/pkg-config/1.md) file.

The code described here uses [**getenv**(3)](/getenv/3.md), which is declared to be not multi-thread-safe. This means that the code calling the functions described here must not call [**setenv**(3)](/setenv/3.md) 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.

## 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.

## SEE ALSO

[**systemd**(1)](/systemd/1.md), [**sd-bus**(3)](/sd-bus/3.md), [**sd\_bus\_slot\_set\_floating**(3)](/sd_bus_slot_set_floating/3.md), [**sd\_bus\_add\_match**(3)](/sd_bus_add_match/3.md), [**sd\_bus\_track\_new**(3)](/sd_bus_track_new/3.md), [**sd\_bus\_slot\_set\_userdata**(3)](/sd_bus_slot_set_userdata/3.md), [**sd\_bus\_track\_set\_userdata**(3)](/sd_bus_track_set_userdata/3.md)
