check geteuid when (un)mount fails with EPERM

Try to give better error messages for this case...

Closes #8478

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
This commit is contained in:
Josh Soref 2019-05-26 00:43:13 -04:00
parent 46df7e6cc9
commit 1479f510fb
1 changed files with 9 additions and 3 deletions

View File

@ -727,12 +727,13 @@ zfs_mount_and_share(libzfs_handle_t *hdl, const char *dataset, zfs_type_t type)
*/
if (zfs_prop_valid_for_type(ZFS_PROP_CANMOUNT, type, B_FALSE) &&
zfs_prop_get_int(zhp, ZFS_PROP_CANMOUNT) == ZFS_CANMOUNT_ON) {
if (geteuid() != 0) {
ret = zfs_mount(zhp, NULL, 0);
if (ret == EPERM && geteuid() != 0) {
(void) fprintf(stderr, gettext("filesystem "
"successfully created, but it may only be "
"mounted by root\n"));
ret = 1;
} else if (zfs_mount(zhp, NULL, 0) != 0) {
} else if (ret != 0) {
(void) fprintf(stderr, gettext("filesystem "
"successfully created, but not mounted\n"));
ret = 1;
@ -6780,9 +6781,14 @@ unshare_unmount_path(int op, char *path, int flags, boolean_t is_manual)
}
(void) fprintf(stderr, gettext("warning: %s not in"
"/proc/self/mounts\n"), path);
if ((ret = umount2(path, flags)) != 0)
if ((ret = umount2(path, flags)) != 0) {
(void) fprintf(stderr, gettext("%s: %s\n"), path,
strerror(errno));
if (ret == EPERM && geteuid() != 0) {
(void) fprintf(stderr, gettext("filesystems "
"may only be unmounted by root\n"));
}
}
return (ret != 0);
}