sd-event: introduce sd_event_source_get_inotify_path()
This may be useful when there are multiple inotify event sources exist. Without this, users need to manage the event sources and paths.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user