]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: (optlist) de-duplicate also according to invert mask
authorKarel Zak <kzak@redhat.com>
Thu, 18 Aug 2022 09:59:08 +0000 (11:59 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 3 Jan 2023 11:58:42 +0000 (12:58 +0100)
The last option is the winner, it means "noexec,exec" is "exec".

Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/optlist.c

index 8b2fe722932274b49b116d5778a4b7d1ba710f76..7d66d1aa31b8d2c9936dcfb9755d868346790419 100644 (file)
@@ -293,15 +293,29 @@ int mnt_optlist_merge_opts(struct libmnt_optlist *ls)
 
                mnt_reset_iter(&xtr, MNT_ITER_FORWARD);
                while (mnt_optlist_next_opt(ls, &xtr, &x) == 0) {
+                       int rem = 0;
+
                        if (opt == x)
                                break;  /* no another instance */
 
-                       if (is_equal_opts(opt, x)) {
+                       /* remove duplicate option */
+                       if (is_equal_opts(opt, x))
+                               rem = 1;
+
+                       /* remove inverted option */
+                       else if (opt->ent && x->ent
+                           && opt->ent->id == x->ent->id
+                           && (opt->ent->mask & MNT_INVERT
+                                   || x->ent->mask & MNT_INVERT))
+                               rem = 1;
+
+                       if (rem) {
                                /* me sure @itr does not point to removed item */
                                if (itr.p == &x->opts)
                                        itr.p = x->opts.prev;
                                mnt_optlist_remove_opt(ls, x);
                        }
+
                }
        }
 
@@ -590,6 +604,8 @@ int mnt_optlist_get_flags(struct libmnt_optlist *ls, unsigned long *flags,
        mnt_reset_iter(&itr, MNT_ITER_FORWARD);
 
        while (mnt_optlist_next_opt(ls, &itr, &opt) == 0) {
+               if (map != opt->map)
+                       continue;
                if (!opt->ent || !opt->ent->id)
                        continue;
                if (opt->external && !(what & MNT_OL_FLTR_ALL))