From 1479f510fb59811eb014fa401d623c128be5b2d8 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sun, 26 May 2019 00:43:13 -0400 Subject: [PATCH] check geteuid when (un)mount fails with EPERM Try to give better error messages for this case... Closes #8478 Signed-off-by: Josh Soref --- cmd/zfs/zfs_main.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cmd/zfs/zfs_main.c b/cmd/zfs/zfs_main.c index 214a437c5d..afaa5e881b 100644 --- a/cmd/zfs/zfs_main.c +++ b/cmd/zfs/zfs_main.c @@ -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); }