From: Karel Zak Date: Thu, 9 Feb 2023 13:11:00 +0000 (+0100) Subject: umount: don't ignore --quiet for non-root users X-Git-Tag: v2.39-rc1~85 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0888529ceba19b7150715a52856ae875a6dcca9b;p=thirdparty%2Futil-linux.git umount: don't ignore --quiet for non-root users The command line option --quiet suppresses 'not mounted' error messages. This does not work for non-root users because libmount does not call umount(2) syscall, and in this case, the library returns -EPERM. Fixes: https://github.com/util-linux/util-linux/issues/2060 Signed-off-by: Karel Zak --- diff --git a/sys-utils/umount.c b/sys-utils/umount.c index f5931767cc..e579fb786b 100644 --- a/sys-utils/umount.c +++ b/sys-utils/umount.c @@ -154,18 +154,27 @@ static void success_message(struct libmnt_context *cxt) warnx(_("%s unmounted"), tgt); } -static int mk_exit_code(struct libmnt_context *cxt, int rc) +static int mk_exit_code(struct libmnt_context *cxt, int api_rc) { char buf[BUFSIZ] = { 0 }; + int rc; - rc = mnt_context_get_excode(cxt, rc, buf, sizeof(buf)); + rc = mnt_context_get_excode(cxt, api_rc, buf, sizeof(buf)); /* suppress "not mounted" error message */ - if (quiet && - rc == MNT_EX_FAIL && - mnt_context_syscall_called(cxt) && - mnt_context_get_syscall_errno(cxt) == EINVAL) - return rc; + if (quiet) { + switch (rc) { + case MNT_EX_USAGE: + if (api_rc == -EPERM) /* non-root user */ + return rc; + break; + case MNT_EX_FAIL: + if (mnt_context_syscall_called(cxt) && + mnt_context_get_syscall_errno(cxt) == EINVAL) + return rc; + break; + } + } /* print errors/warnings */ if (*buf) {