]> 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)
committerJohn Keeping <jkeeping@inmusicbrands.com>
Tue, 6 Aug 2024 17:16:00 +0000 (18:16 +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>
libmount/src/context_mount.c

index a685acc1619f71b704cdd49b6c588b6eb02b5697..dc800c6085dd4152f7ebe4a345992c973a12d35e 100644 (file)
@@ -581,6 +581,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)
 {
@@ -666,10 +675,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);