From: John Keeping Date: Tue, 6 Aug 2024 17:16:00 +0000 (+0100) Subject: libmount: extract common error handling function X-Git-Tag: v2.40.3~19 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=4fc642f4cbbc3ce9ca9d791d9c5369f018f5c9c7;p=thirdparty%2Futil-linux.git libmount: extract common error handling function 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 (cherry picked from commit 7903560fa34fe1810cdaf3dcda7cafbdefb488ac) --- diff --git a/libmount/src/context_mount.c b/libmount/src/context_mount.c index 1966f5be1..a75d1ed52 100644 --- a/libmount/src/context_mount.c +++ b/libmount/src/context_mount.c @@ -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);