diff --git a/man/sd_event_add_inotify.xml b/man/sd_event_add_inotify.xml
index 2e2f5f25e4..636f37b001 100644
--- a/man/sd_event_add_inotify.xml
+++ b/man/sd_event_add_inotify.xml
@@ -19,6 +19,7 @@
sd_event_add_inotify
sd_event_add_inotify_fd
sd_event_source_get_inotify_mask
+ sd_event_source_get_inotify_path
sd_event_inotify_handler_t
Add an "inotify" file system inode event source to an event loop
@@ -63,6 +64,12 @@
uint32_t *ret
+
+ int sd_event_source_get_inotify_path
+ sd_event_source *source
+ char **ret
+
+
@@ -133,6 +140,11 @@
event source created previously with sd_event_add_inotify(). It takes the event source object
as the source parameter and a pointer to a uint32_t variable to return the mask
in.
+
+ sd_event_source_get_inotify_path() retrieves the target path of the configured
+ inotify watch of an event source created previously with sd_event_add_inotify(). It
+ takes the event source object as the source parameter and a pointer to a
+ char ** variable to return the path in. The caller needs to free the returned path.
@@ -163,7 +175,12 @@
-ESTALE
- The event loop is already terminated.
+
+ Returned by sd_event_source_add_inotify() or
+ sd_event_source_add_inotify_fd() when the event loop is already terminated.
+ Returned by sd_event_source_get_inotify_path() when no active inode data is
+ assigned to the event source, e.g. when the event source is disabled.
+
@@ -217,6 +234,7 @@
sd_event_add_inotify(), and
sd_event_source_get_inotify_mask() were added in version 239.
sd_event_add_inotify_fd() was added in version 250.
+ sd_event_source_get_inotify_path() was added in version 256.
diff --git a/src/libsystemd/libsystemd.sym b/src/libsystemd/libsystemd.sym
index d23da4c151..89de4b37ca 100644
--- a/src/libsystemd/libsystemd.sym
+++ b/src/libsystemd/libsystemd.sym
@@ -840,4 +840,5 @@ global:
sd_bus_creds_get_pidfd_dup;
sd_bus_creds_new_from_pidfd;
sd_journal_stream_fd_with_namespace;
+ sd_event_source_get_inotify_path;
} LIBSYSTEMD_255;
diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c
index c4de472106..ea35293ec4 100644
--- a/src/libsystemd/sd-event/sd-event.c
+++ b/src/libsystemd/sd-event/sd-event.c
@@ -3292,6 +3292,18 @@ _public_ int sd_event_source_get_inotify_mask(sd_event_source *s, uint32_t *ret)
return 0;
}
+_public_ int sd_event_source_get_inotify_path(sd_event_source *s, char **ret) {
+ assert_return(s, -EINVAL);
+ assert_return(ret, -EINVAL);
+ assert_return(s->type == SOURCE_INOTIFY, -EDOM);
+ assert_return(!event_origin_changed(s->event), -ECHILD);
+
+ if (!s->inotify.inode_data || s->inotify.inode_data->fd < 0)
+ return -ESTALE;
+
+ return fd_get_path(s->inotify.inode_data->fd, ret);
+}
+
_public_ int sd_event_source_set_prepare(sd_event_source *s, sd_event_handler_t callback) {
int r;
diff --git a/src/libsystemd/sd-event/test-event.c b/src/libsystemd/sd-event/test-event.c
index e02de097ba..87f704ecb1 100644
--- a/src/libsystemd/sd-event/test-event.c
+++ b/src/libsystemd/sd-event/test-event.c
@@ -475,6 +475,7 @@ static int delete_self_handler(sd_event_source *s, const struct inotify_event *e
static void test_inotify_one(unsigned n_create_events) {
_cleanup_(rm_rf_physical_and_freep) char *p = NULL;
+ _cleanup_free_ char *pp = NULL;
sd_event_source *a = NULL, *b = NULL, *c = NULL, *d = NULL;
struct inotify_context context = {
.n_create_events = n_create_events,
@@ -500,6 +501,16 @@ static void test_inotify_one(unsigned n_create_events) {
assert_se(sd_event_source_set_description(b, "1") >= 0);
assert_se(sd_event_source_set_description(c, "2") >= 0);
+ assert_se(sd_event_source_get_inotify_path(a, &pp) >= 0);
+ assert_se(path_equal_or_inode_same(pp, p, 0));
+ pp = mfree(pp);
+ assert_se(sd_event_source_get_inotify_path(b, &pp) >= 0);
+ assert_se(path_equal_or_inode_same(pp, p, 0));
+ pp = mfree(pp);
+ assert_se(sd_event_source_get_inotify_path(b, &pp) >= 0);
+ assert_se(path_equal_or_inode_same(pp, p, 0));
+ pp = mfree(pp);
+
q = strjoina(p, "/sub");
assert_se(touch(q) >= 0);
assert_se(sd_event_add_inotify(e, &d, q, IN_DELETE_SELF, delete_self_handler, &context) >= 0);
diff --git a/src/systemd/sd-event.h b/src/systemd/sd-event.h
index 49d6975967..e306c891cb 100644
--- a/src/systemd/sd-event.h
+++ b/src/systemd/sd-event.h
@@ -161,6 +161,7 @@ int sd_event_source_send_child_signal(sd_event_source *s, int sig, const siginfo
int sd_event_source_send_child_signal(sd_event_source *s, int sig, const void *si, unsigned flags);
#endif
int sd_event_source_get_inotify_mask(sd_event_source *s, uint32_t *ret);
+int sd_event_source_get_inotify_path(sd_event_source *s, char **ret);
int sd_event_source_set_memory_pressure_type(sd_event_source *e, const char *ty);
int sd_event_source_set_memory_pressure_period(sd_event_source *s, uint64_t threshold_usec, uint64_t window_usec);
int sd_event_source_set_destroy_callback(sd_event_source *s, sd_event_destroy_t callback);