From: Karel Zak Date: Wed, 21 May 2025 10:39:17 +0000 (+0200) Subject: libmount: (monitor) support additional monitor identifiers X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3285ebe18773dfcd6ed7ae7a1a9952d0abb3fb04;p=thirdparty%2Futil-linux.git libmount: (monitor) support additional monitor identifiers This is necessary to support multiple monitors of the same type. Currently, only one monitor per type is supported. Signed-off-by: Karel Zak --- diff --git a/libmount/src/monitor.c b/libmount/src/monitor.c index fb68d0d67..3044dcf68 100644 --- a/libmount/src/monitor.c +++ b/libmount/src/monitor.c @@ -124,6 +124,7 @@ struct monitor_entry *monitor_new_entry(struct libmnt_monitor *mn) list_add_tail(&me->ents, &mn->ents); me->fd = -1; + me->id = -1; return me; } @@ -153,14 +154,14 @@ static int monitor_next_entry(struct libmnt_monitor *mn, } /* returns entry by type */ -struct monitor_entry *monitor_get_entry(struct libmnt_monitor *mn, int type) +struct monitor_entry *monitor_get_entry(struct libmnt_monitor *mn, int type, int id) { struct libmnt_iter itr; struct monitor_entry *me; mnt_reset_iter(&itr, MNT_ITER_FORWARD); while (monitor_next_entry(mn, &itr, &me) == 0) { - if (me->type == type) + if (me->type == type && me->id == id) return me; } return NULL; diff --git a/libmount/src/monitor.h b/libmount/src/monitor.h index a72658e95..6c6ba4450 100644 --- a/libmount/src/monitor.h +++ b/libmount/src/monitor.h @@ -8,6 +8,7 @@ struct monitor_opers; struct monitor_entry { int fd; /* private entry file descriptor */ + int id; /* external identifier (-1 for undefined) */ char *path; /* path to the monitored file */ int type; /* MNT_MONITOR_TYPE_* */ uint32_t events; /* wanted epoll events */ @@ -36,7 +37,7 @@ struct monitor_opers { }; int monitor_modify_epoll(struct libmnt_monitor *mn, struct monitor_entry *me, int enable); -struct monitor_entry *monitor_get_entry(struct libmnt_monitor *mn, int type); +struct monitor_entry *monitor_get_entry(struct libmnt_monitor *mn, int type, int id); struct monitor_entry *monitor_new_entry(struct libmnt_monitor *mn); void free_monitor_entry(struct monitor_entry *me); diff --git a/libmount/src/monitor_mountinfo.c b/libmount/src/monitor_mountinfo.c index 56171fd91..3bffcb31f 100644 --- a/libmount/src/monitor_mountinfo.c +++ b/libmount/src/monitor_mountinfo.c @@ -99,7 +99,7 @@ int mnt_monitor_enable_kernel(struct libmnt_monitor *mn, int enable) if (!mn) return -EINVAL; - me = monitor_get_entry(mn, MNT_MONITOR_TYPE_KERNEL); + me = monitor_get_entry(mn, MNT_MONITOR_TYPE_KERNEL, -1); if (me) { rc = monitor_modify_epoll(mn, me, enable); if (!enable) diff --git a/libmount/src/monitor_utab.c b/libmount/src/monitor_utab.c index d7261a947..593e16329 100644 --- a/libmount/src/monitor_utab.c +++ b/libmount/src/monitor_utab.c @@ -209,7 +209,7 @@ int mnt_monitor_enable_userspace(struct libmnt_monitor *mn, int enable, const ch if (!mn) return -EINVAL; - me = monitor_get_entry(mn, MNT_MONITOR_TYPE_USERSPACE); + me = monitor_get_entry(mn, MNT_MONITOR_TYPE_USERSPACE, -1); if (me) { rc = monitor_modify_epoll(mn, me, enable); if (!enable)