]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: (monitor) support additional monitor identifiers
authorKarel Zak <kzak@redhat.com>
Wed, 21 May 2025 10:39:17 +0000 (12:39 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 6 Aug 2025 12:50:56 +0000 (14:50 +0200)
This is necessary to support multiple monitors of the same type.
Currently, only one monitor per type is supported.

Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/monitor.c
libmount/src/monitor.h
libmount/src/monitor_mountinfo.c
libmount/src/monitor_utab.c

index fb68d0d67aaccac7c30b73562fbd9dd76be1ed49..3044dcf68222cb2fc719ac708baf76ec1d0c8406 100644 (file)
@@ -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;
index a72658e9539c44310e45e8cbabb8bf87a8028e25..6c6ba4450655f64d448e40b00bf9b0f3379caa84 100644 (file)
@@ -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);
 
index 56171fd91a1cb82b59420862b950501a9de9c9c8..3bffcb31fd35a79e15769fae27d519c8cee82d59 100644 (file)
@@ -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)
index d7261a947119204363801193925d2f7adbcc9c81..593e16329608d103c403ad7012af8355110ecfab 100644 (file)
@@ -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)