]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: fix /{etc,proc}/filesystems use
authorKarel Zak <kzak@redhat.com>
Tue, 9 Feb 2021 09:36:04 +0000 (10:36 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 9 Feb 2021 09:36:04 +0000 (10:36 +0100)
* always update context->helper
* consolidate helper and syscall status use

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

index fa8a8c54b56b0e1a5fd98dbd36953a93e58d1f7c..ccd050130e3d5935c5d55cb40895bb28263097ae 100644 (file)
@@ -2101,6 +2101,11 @@ int mnt_context_prepare_helper(struct libmnt_context *cxt, const char *name,
        assert(cxt->fs);
        assert((cxt->flags & MNT_FL_MOUNTFLAGS_MERGED));
 
+       if (cxt->helper) {
+               free(cxt->helper);
+               cxt->helper = NULL;
+       }
+
        if (!type)
                type = mnt_fs_get_fstype(cxt->fs);
 
index dd178617641585544c84844d06eba95e1d9ad705..28ffc88247e25a56aa2792c89b69b7d2a30eeed2 100644 (file)
@@ -773,7 +773,7 @@ static int do_mount(struct libmnt_context *cxt, const char *try_type)
        assert(cxt->fs);
        assert((cxt->flags & MNT_FL_MOUNTFLAGS_MERGED));
 
-       if (try_type && !cxt->helper) {
+       if (try_type) {
                rc = mnt_context_prepare_helper(cxt, "mount", try_type);
                if (rc)
                        return rc;
@@ -860,6 +860,17 @@ static int do_mount(struct libmnt_context *cxt, const char *try_type)
        return rc;
 }
 
+static int is_success_status(struct libmnt_context *cxt)
+{
+       if (mnt_context_helper_executed(cxt))
+               return mnt_context_get_helper_status(cxt) == 0;
+
+       if (mnt_context_syscall_called(cxt))
+               return mnt_context_get_status(cxt) == 1;
+
+       return 0;
+}
+
 /* try mount(2) for all items in comma separated list of the filesystem @types */
 static int do_mount_by_types(struct libmnt_context *cxt, const char *types)
 {
@@ -900,7 +911,7 @@ static int do_mount_by_types(struct libmnt_context *cxt, const char *types)
                        rc = do_mount(cxt, p);
                p = end ? end + 1 : NULL;
                free(autotype);
-       } while (!mnt_context_get_status(cxt) && p);
+       } while (!is_success_status(cxt) && p);
 
        free(p0);
        return rc;
@@ -943,8 +954,9 @@ static int do_mount_by_pattern(struct libmnt_context *cxt, const char *pattern)
                return -MNT_ERR_NOFSTYPE;
 
        for (fp = filesystems; *fp; fp++) {
+               DBG(CXT, ul_debugobj(cxt, " ##### trying '%s'", *fp));
                rc = do_mount(cxt, *fp);
-               if (mnt_context_get_status(cxt))
+               if (is_success_status(cxt))
                        break;
                if (mnt_context_get_syscall_errno(cxt) != EINVAL &&
                    mnt_context_get_syscall_errno(cxt) != ENODEV)