diff --git a/man/rules/meson.build b/man/rules/meson.build
index efbd940fe0..04f03c6786 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',
@@ -277,9 +280,11 @@ manpages = [
'sd_event_source',
'sd_event_source_get_io_events',
'sd_event_source_get_io_fd',
+ 'sd_event_source_get_io_fd_own',
'sd_event_source_get_io_revents',
'sd_event_source_set_io_events',
- 'sd_event_source_set_io_fd'],
+ 'sd_event_source_set_io_fd',
+ 'sd_event_source_set_io_fd_own'],
''],
['sd_event_add_signal',
'3',
@@ -314,6 +319,10 @@ manpages = [
'3',
['sd_event_source_get_description'],
''],
+ ['sd_event_source_set_destroy_callback',
+ '3',
+ ['sd_event_destroy_t', 'sd_event_source_get_destroy_callback'],
+ ''],
['sd_event_source_set_enabled',
'3',
['SD_EVENT_OFF',
diff --git a/man/sd_bus_slot_set_destroy_callback.xml b/man/sd_bus_slot_set_destroy_callback.xml
index 6334444f9a..a54b7e2d61 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/man/sd_event_add_io.xml b/man/sd_event_add_io.xml
index d5ef462e53..bd513a7814 100644
--- a/man/sd_event_add_io.xml
+++ b/man/sd_event_add_io.xml
@@ -38,6 +38,8 @@
sd_event_source_get_io_revents
sd_event_source_get_io_fd
sd_event_source_set_io_fd
+ sd_event_source_get_io_fd_own
+ sd_event_source_set_io_fd_own
sd_event_source
sd_event_io_handler_t
@@ -97,6 +99,17 @@
int fd
+
+ int sd_event_source_get_io_fd_own
+ sd_event_source *source
+
+
+
+ int sd_event_source_set_io_fd_own
+ sd_event_source *source
+ int b
+
+
@@ -212,6 +225,17 @@
changes the UNIX file descriptor of an I/O event source created
previously with sd_event_add_io(). It takes
the event source object and the new file descriptor.
+
+ sd_event_source_set_io_fd_own() controls whether the file descriptor of the event source
+ shall be closed automatically when the event source is freed, i.e. whether it shall be considered 'owned' by the
+ event source object. By default it is not closed automatically, and the application has to do this on its own. The
+ b parameter is a boolean parameter: if zero, the file descriptor is not closed automatically
+ when the event source is freed, otherwise it is closed.
+
+ sd_event_source_get_io_fd_own() may be used to query the current setting of the file
+ descriptor ownership boolean flag as set with sd_event_source_set_io_fd_own(). It returns
+ positive if the file descriptor is closed automatically when the event source is destroyed, zero if not, and
+ negative on error.
diff --git a/man/sd_event_source_set_destroy_callback.xml b/man/sd_event_source_set_destroy_callback.xml
new file mode 100644
index 0000000000..34f7652c86
--- /dev/null
+++ b/man/sd_event_source_set_destroy_callback.xml
@@ -0,0 +1,112 @@
+
+
+
+
+
+
+
+
+ sd_event_source_set_destroy_callback
+ systemd
+
+
+
+ sd_event_source_set_destroy_callback
+ 3
+
+
+
+ sd_event_source_set_destroy_callback
+ sd_event_source_get_destroy_callback
+ sd_event_destroy_t
+
+ Define the callback function for resource cleanup.
+
+
+
+
+ #include <systemd/sd-event.h>
+
+
+ typedef int (*sd_event_destroy_t)
+ void *userdata
+
+
+
+ int sd_event_source_set_destroy_callback
+ sd_event_source *source
+ sd_event_destroy_t callback
+
+
+
+ int sd_event_source_get_destroy_callback
+ sd_event_source *source
+ sd_event_destroy_t *callback
+
+
+
+
+
+
+ Description
+
+ sd_event_source_set_destroy_callback() sets callback as the
+ callback function to be called right before the event source object source is
+ deallocated. The userdata pointer from the event source object will be passed as the
+ userdata parameter. This pointer can be set by an argument to the constructor functions, see
+ sd_event_add_io3, or directly,
+ see
+ sd_event_source_set_userdata3.
+ This callback function is called even if userdata is NULL. Note that
+ this callback is invoked at a time where the event source object itself is already invalidated, and executing
+ operations or taking new references to the event source object is not permissible.
+
+ sd_event_source_get_destroy_callback() returns the current callback
+ for source in the callback parameter.
+
+
+
+ Return Value
+
+ On success, sd_event_source_set_destroy_callback() returns 0 or a positive integer. On
+ failure, it returns a negative errno-style error code.
+
+ sd_event_source_get_destroy_callback() returns positive if the destroy callback function
+ is set, 0 if not. On failure, returns a negative errno-style error code.
+
+
+
+ Errors
+
+ Returned errors may indicate the following problems:
+
+
+
+ -EINVAL
+
+ The source parameter is NULL.
+
+
+
+
+
+
+
+ See Also
+
+
+ systemd1,
+ sd-event3,
+ sd_event_add_io3,
+ sd_event_add_time3,
+ sd_event_add_signal3,
+ sd_event_add_child3,
+ sd_event_add_inotify3,
+ sd_event_add_defer3,
+ sd_event_source_set_userdata3
+
+
+
+
diff --git a/src/libsystemd/libsystemd.sym b/src/libsystemd/libsystemd.sym
index dc9c2d241a..270fe37e9f 100644
--- a/src/libsystemd/libsystemd.sym
+++ b/src/libsystemd/libsystemd.sym
@@ -565,6 +565,10 @@ 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;
+ sd_event_source_set_destroy_callback;
+ sd_event_source_get_destroy_callback;
} LIBSYSTEMD_238;
diff --git a/src/libsystemd/sd-bus/bus-track.c b/src/libsystemd/sd-bus/bus-track.c
index 168c6c5ac7..1819eaffd4 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/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c
index 1b983dbe37..196b90d59b 100644
--- a/src/libsystemd/sd-event/sd-event.c
+++ b/src/libsystemd/sd-event/sd-event.c
@@ -106,6 +106,8 @@ struct sd_event_source {
uint64_t pending_iteration;
uint64_t prepare_iteration;
+ sd_event_destroy_t destroy_callback;
+
LIST_FIELDS(sd_event_source, sources);
union {
@@ -1016,7 +1018,10 @@ static void source_free(sd_event_source *s) {
source_disconnect(s);
if (s->type == SOURCE_IO && s->io.owned)
- safe_close(s->io.fd);
+ s->io.fd = safe_close(s->io.fd);
+
+ if (s->destroy_callback)
+ s->destroy_callback(s->userdata);
free(s->description);
free(s);
@@ -3775,3 +3780,19 @@ _public_ int sd_event_get_iteration(sd_event *e, uint64_t *ret) {
*ret = e->iteration;
return 0;
}
+
+_public_ int sd_event_source_set_destroy_callback(sd_event_source *s, sd_event_destroy_t callback) {
+ assert_return(s, -EINVAL);
+
+ s->destroy_callback = callback;
+ return 0;
+}
+
+_public_ int sd_event_source_get_destroy_callback(sd_event_source *s, sd_event_destroy_t *ret) {
+ assert_return(s, -EINVAL);
+
+ if (ret)
+ *ret = s->destroy_callback;
+
+ return !!s->destroy_callback;
+}
diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h
index b2394763c1..a1b1570663 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);
diff --git a/src/systemd/sd-event.h b/src/systemd/sd-event.h
index 28939ca550..fc5a75b6b6 100644
--- a/src/systemd/sd-event.h
+++ b/src/systemd/sd-event.h
@@ -80,6 +80,7 @@ typedef int (*sd_event_child_handler_t)(sd_event_source *s, const siginfo_t *si,
typedef void* sd_event_child_handler_t;
#endif
typedef int (*sd_event_inotify_handler_t)(sd_event_source *s, const struct inotify_event *event, void *userdata);
+typedef void (*sd_event_destroy_t)(void *userdata);
int sd_event_default(sd_event **e);
@@ -143,6 +144,8 @@ int sd_event_source_get_time_clock(sd_event_source *s, clockid_t *clock);
int sd_event_source_get_signal(sd_event_source *s);
int sd_event_source_get_child_pid(sd_event_source *s, pid_t *pid);
int sd_event_source_get_inotify_mask(sd_event_source *s, uint32_t *ret);
+int sd_event_source_set_destroy_callback(sd_event_source *s, sd_event_destroy_t callback);
+int sd_event_source_get_destroy_callback(sd_event_source *s, sd_event_destroy_t *ret);
/* Define helpers so that __attribute__((cleanup(sd_event_unrefp))) and similar may be used. */
_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_event, sd_event_unref);