]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
umount: don't ignore --quiet for non-root users
authorKarel Zak <kzak@redhat.com>
Thu, 9 Feb 2023 13:11:00 +0000 (14:11 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 9 Feb 2023 13:11:00 +0000 (14:11 +0100)
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 <kzak@redhat.com>
sys-utils/umount.c

index f5931767cc5f3de577e13d9559bdb2d125aeee21..e579fb786b77793bc04c9d56db0ed803740be2c5 100644 (file)
@@ -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) {