libmount: fix /{etc,proc}/filesystems use

* always update context->helper
* consolidate helper and syscall status use

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2021-02-09 10:36:04 +01:00
parent d4b5887354
commit b6787fca02
2 changed files with 20 additions and 3 deletions

View 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);

View 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)