]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: extract common error handling function
authorJohn Keeping <jkeeping@inmusicbrands.com>
Tue, 6 Aug 2024 17:16:00 +0000 (18:16 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 3 Jan 2025 11:42:39 +0000 (12:42 +0100)
Extract the logic for whether to continue trying more filesystem types
to a function so that it can be reused to make this consistent between
do_mount_by_pattern() and do_mount_by_types().

Signed-off-by: John Keeping <jkeeping@inmusicbrands.com>
(cherry picked from commit 7903560fa34fe1810cdaf3dcda7cafbdefb488ac)

libmount/src/context_mount.c

index 1966f5be1b5b2ece71dd7ccf040920791058a76e..a75d1ed526a95f6670eb64eb3223016cf06e152b 100644 (file)
@@ -577,6 +577,15 @@ static int is_success_status(struct libmnt_context *cxt)
        return 0;
 }
 
+static int is_termination_status(struct libmnt_context *cxt)
+{
+       if (is_success_status(cxt))
+               return 1;
+
+       return mnt_context_get_syscall_errno(cxt) != EINVAL &&
+              mnt_context_get_syscall_errno(cxt) != ENODEV;
+}
+
 /* 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)
 {
@@ -662,10 +671,7 @@ static int do_mount_by_pattern(struct libmnt_context *cxt, const char *pattern)
        for (fp = filesystems; *fp; fp++) {
                DBG(CXT, ul_debugobj(cxt, " ##### trying '%s'", *fp));
                rc = do_mount(cxt, *fp);
-               if (is_success_status(cxt))
-                       break;
-               if (mnt_context_get_syscall_errno(cxt) != EINVAL &&
-                   mnt_context_get_syscall_errno(cxt) != ENODEV)
+               if (is_termination_status(cxt))
                        break;
        }
        mnt_free_filesystems(filesystems);