diff --git a/man/rules/meson.build b/man/rules/meson.build
index efbd940fe0c..765ff04b7d3 100644
--- a/man/rules/meson.build
+++ b/man/rules/meson.build
@@ -233,7 +233,10 @@ manpages = [
['sd_bus_set_watch_bind', '3', ['sd_bus_get_watch_bind'], ''],
['sd_bus_slot_set_destroy_callback',
'3',
- ['sd_bus_slot_get_destroy_callback'],
+ ['sd_bus_destroy_t',
+ 'sd_bus_slot_get_destroy_callback',
+ 'sd_bus_track_get_destroy_callback',
+ 'sd_bus_track_set_destroy_callback'],
''],
['sd_bus_slot_set_floating', '3', ['sd_bus_slot_get_floating'], ''],
['sd_bus_track_add_name',
diff --git a/man/sd_bus_slot_set_destroy_callback.xml b/man/sd_bus_slot_set_destroy_callback.xml
index 6334444f9a6..a54b7e2d613 100644
--- a/man/sd_bus_slot_set_destroy_callback.xml
+++ b/man/sd_bus_slot_set_destroy_callback.xml
@@ -20,6 +20,9 @@
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.
@@ -44,35 +47,54 @@
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 specified as an argument to the constuctor functions, see
- sd_bus_add_match3,
- or directly, see
- sd_bus_set_userdata3.
- This callback function is called even if userdata is
- NULL.
+ 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_match3, or directly,
+ see sd_bus_slot_set_userdata3.
+ 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_new3.
Return Value
- On success, sd_bus_slot_set_destroy_callback() returns 0 or a
- positive integer. On failure, it returns a negative errno-style error code.
+ 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() returns 1 if the destroy callback
- function is set, 0 if not. On failure, it returns 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.
@@ -84,8 +106,8 @@
-EINVAL
- The slot parameter is NULL.
-
+ The slot or track parameter is
+ NULL.
@@ -98,7 +120,11 @@
systemd1,
sd-bus3,
- sd_bus_slot_set_floating3
+ sd_bus_slot_set_floating3,
+ sd_bus_add_match3,
+ sd_bus_track_new3,
+ sd_bus_slot_set_userdata3,
+ sd_bus_track_set_userdata3
diff --git a/src/libsystemd/libsystemd.sym b/src/libsystemd/libsystemd.sym
index dc9c2d241a6..7907bfb5df4 100644
--- a/src/libsystemd/libsystemd.sym
+++ b/src/libsystemd/libsystemd.sym
@@ -565,6 +565,8 @@ global:
sd_bus_slot_set_floating;
sd_bus_slot_get_destroy_callback;
sd_bus_slot_set_destroy_callback;
+ sd_bus_track_get_destroy_callback;
+ sd_bus_track_set_destroy_callback;
sd_event_add_inotify;
sd_event_source_get_inotify_mask;
} LIBSYSTEMD_238;
diff --git a/src/libsystemd/sd-bus/bus-track.c b/src/libsystemd/sd-bus/bus-track.c
index 168c6c5ac72..1819eaffd4a 100644
--- a/src/libsystemd/sd-bus/bus-track.c
+++ b/src/libsystemd/sd-bus/bus-track.c
@@ -31,6 +31,7 @@ struct sd_bus_track {
bool in_queue:1; /* In bus->track_queue? */
bool modified:1;
bool recursive:1;
+ sd_bus_destroy_t destroy_callback;
LIST_FIELDS(sd_bus_track, tracks);
};
@@ -164,18 +165,21 @@ _public_ sd_bus_track* sd_bus_track_unref(sd_bus_track *track) {
return NULL;
assert(track->n_ref > 0);
+ track->n_ref--;
- if (track->n_ref > 1) {
- track->n_ref--;
+ if (track->n_ref > 0)
return NULL;
- }
if (track->in_list)
LIST_REMOVE(tracks, track->bus->tracks, track);
bus_track_remove_from_queue(track);
- hashmap_free_with_destructor(track->names, track_item_free);
- sd_bus_unref(track->bus);
+ track->names = hashmap_free_with_destructor(track->names, track_item_free);
+ track->bus = sd_bus_unref(track->bus);
+
+ if (track->destroy_callback)
+ track->destroy_callback(track->userdata);
+
return mfree(track);
}
@@ -439,6 +443,22 @@ _public_ void *sd_bus_track_set_userdata(sd_bus_track *track, void *userdata) {
return ret;
}
+_public_ int sd_bus_track_set_destroy_callback(sd_bus_track *track, sd_bus_destroy_t callback) {
+ assert_return(track, -EINVAL);
+
+ track->destroy_callback = callback;
+ return 0;
+}
+
+_public_ int sd_bus_track_get_destroy_callback(sd_bus_track *track, sd_bus_destroy_t *ret) {
+ assert_return(track, -EINVAL);
+
+ if (ret)
+ *ret = track->destroy_callback;
+
+ return !!track->destroy_callback;
+}
+
_public_ int sd_bus_track_set_recursive(sd_bus_track *track, int b) {
assert_return(track, -EINVAL);
diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h
index b2394763c1c..a1b15706633 100644
--- a/src/systemd/sd-bus.h
+++ b/src/systemd/sd-bus.h
@@ -485,6 +485,9 @@ const char* sd_bus_track_contains(sd_bus_track *track, const char *name);
const char* sd_bus_track_first(sd_bus_track *track);
const char* sd_bus_track_next(sd_bus_track *track);
+int sd_bus_track_set_destroy_callback(sd_bus_track *s, sd_bus_destroy_t callback);
+int sd_bus_track_get_destroy_callback(sd_bus_track *s, sd_bus_destroy_t *ret);
+
/* Define helpers so that __attribute__((cleanup(sd_bus_unrefp))) and similar may be used. */
_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_bus, sd_bus_unref);
_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_bus, sd_bus_flush_close_unref);