On 2020-07-31 16:32, Nick Alcock wrote:
> I get an ERROR when running rmdir/ignore.sh as root (but not when
> running as non-root). [...]

> ERROR: tests/rmdir/ignore
> =========================
[...]
> + mkdir -p x/y
> + chmod a-w x
> + returns_ 1 rmdir --ignore-fail-on-non-empty x/y
> + fail=1

Thanks for reporting this issue.

Indeed, this test does not work as root.
The comment in the test explains that it expects an EPERM error:

  # Ensure that with --ignore-fail-on-non-empty, we still fail, e.g., for EPERM.
  # Between 6.11 and 8.31, the following rmdir would mistakenly succeed.
  mkdir -p x/y || framework_failure_
  chmod a-w x || framework_failure_
  returns_ 1 rmdir --ignore-fail-on-non-empty x/y || fail=1

but root does not see the EPERM; strace output:

  ...
  rmdir("x/y")                            = 0
  close(1)                                = 0
  close(2)                                = 0
  exit_group(0)                           = ?
  +++ exited with 0 +++

The attached patch adds guards around the parts of the test which
only work as non-privileged user.

Have a nice day,
Berny
>From c0e5f8c59b951ae13ca9cb9945cd77163489e1d9 Mon Sep 17 00:00:00 2001
From: Bernhard Voelker <m...@bernhard-voelker.de>
Date: Fri, 31 Jul 2020 19:49:35 +0200
Subject: [PATCH] tests: skip some parts of 'tests/rmdir/ignore.sh' if run as
 root

Parts of this test expect that the rmdir syscall returns with EPERM,
but the root user does not see that.

* tests/rmdir/ignore.sh: Add uid_is_privileged_ guards around parts
of the test which expect rmdir() to fail with EPERM.

Reported by Nick Alcock <n...@esperi.org.uk> in
https://bugs.gnu.org/42633
---
 tests/rmdir/ignore.sh | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/tests/rmdir/ignore.sh b/tests/rmdir/ignore.sh
index 65e92d012..b26ac533a 100755
--- a/tests/rmdir/ignore.sh
+++ b/tests/rmdir/ignore.sh
@@ -33,17 +33,24 @@ test -d "$cwd/a/b/c" && fail=1
 # Between 6.11 and 8.31, the following rmdir would mistakenly succeed.
 mkdir -p x/y || framework_failure_
 chmod a-w x || framework_failure_
-returns_ 1 rmdir --ignore-fail-on-non-empty x/y || fail=1
+
+if ! uid_is_privileged_; then  # root does not get EPERM.
+  returns_ 1 rmdir --ignore-fail-on-non-empty x/y || fail=1
+fi
+
 test -d x/y || fail=1
 # Between 6.11 and 8.31, the following rmdir would mistakenly fail,
 # and also give a non descript error
 touch x/y/z || framework_failure_
 rmdir --ignore-fail-on-non-empty x/y || fail=1
 test -d x/y || fail=1
-# assume empty dir if unreadable entries (so failure to remove diagnosed)
-rm x/y/z || framework_failure_
-chmod a-r x/y || framework_failure_
-returns_ 1 rmdir --ignore-fail-on-non-empty x/y || fail=1
-test -d x/y || fail=1
+
+if ! uid_is_privileged_; then  # root does not get EPERM.
+  # assume empty dir if unreadable entries (so failure to remove diagnosed)
+  rm x/y/z || framework_failure_
+  chmod a-r x/y || framework_failure_
+  returns_ 1 rmdir --ignore-fail-on-non-empty x/y || fail=1
+  test -d x/y || fail=1
+fi
 
 Exit $fail
-- 
2.27.0

Reply via email to