]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: use MNT_ERR_APPLYFLAGS for failed mount_setattr()
authorKarel Zak <kzak@redhat.com>
Tue, 10 Jan 2023 11:40:47 +0000 (12:40 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 10 Jan 2023 11:40:47 +0000 (12:40 +0100)
The classic mount(2) based version uses MNT_ERR_APPLYFLAGS when not
able to set flags and errno is EINVAL. This is expected by
mnt_context_get_mount_excode() where libmount generates error messages
for mount(8).

Expected is:

 # mount --make-private /mnt/test
 mount: /mnt/test: not mount point or bad option.

rather than generic error:

 mount: /mnt/test: wrong fs type, bad option, bad superblock on none ...

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

index 6f3dfca0bc3da84382489c4e5a351879969adddf..1c5fcc8e79a5ef192959089cd9897a3b4f4a9876 100644 (file)
@@ -348,6 +348,9 @@ static int hook_set_vfsflags(struct libmnt_context *cxt,
 
        rc = mount_setattr(api->fd_tree, "", callflags, &attr, sizeof(attr));
        set_syscall_status(cxt, "move_setattr", rc == 0);
+
+       if (rc && errno == EINVAL)
+               return -MNT_ERR_APPLYFLAGS;
 done:
        return rc == 0 ? 0 : -errno;
 }
@@ -405,6 +408,9 @@ static int hook_set_propagation(struct libmnt_context *cxt,
 
                rc = mount_setattr(api->fd_tree, "", flgs, &attr, sizeof(attr));
                set_syscall_status(cxt, "move_setattr", rc == 0);
+
+               if (rc && errno == EINVAL)
+                       return -MNT_ERR_APPLYFLAGS;
                if (rc != 0)
                        break;
        }