]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: improve checks for setuidgid-using root-only tests
authorJim Meyering <meyering@redhat.com>
Thu, 6 Sep 2012 10:00:16 +0000 (12:00 +0200)
committerJim Meyering <meyering@redhat.com>
Fri, 7 Sep 2012 09:03:24 +0000 (11:03 +0200)
* init.cfg (setuidgid_has_perm_): New function.
(require_root_): Use it.
Improved-by: Bernhard Voelker
* NEWS (Build-related): Mention the improvement.

NEWS
init.cfg

diff --git a/NEWS b/NEWS
index 995fafb77699753cca284a31c73903c225c7b52f..e90da13e017cec6f1cbffeb3e95e3d0f281fe096 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -34,6 +34,14 @@ GNU coreutils NEWS                                    -*- outline -*-
   on those file systems, rather than the default (for unknown file system
   types) of issuing a warning and reverting to polling.
 
+** Build-related
+
+  root-only tests now check for permissions of our dummy user,
+  $NON_ROOT_USERNAME, before trying to run binaries from the build directory.
+  Before, we would get hard-to-diagnose reports of failing root-only tests.
+  Now, those tests are skipped with a useful diagnostic when the root tests
+  are run without following the instructions in README.
+
 
 * Noteworthy changes in release 8.19 (2012-08-20) [stable]
 
index 13cac74664c1de40379f18652861ece9688ee3b7..304b9184696b2fe25716a39f2cf66bfdfac2f5c7 100644 (file)
--- a/init.cfg
+++ b/init.cfg
@@ -346,11 +346,31 @@ or use the shortcut target of the toplevel Makefile,
   fi
 }
 
+# Test whether we can run our just-built rm setuidgid-to-root,
+# i.e., that $NON_ROOT_USERNAME has access to the build directory.
+setuidgid_has_perm_()
+{
+  local rm_version=$(
+    setuidgid $NON_ROOT_USERNAME env PATH="$PATH" rm --version |
+    sed -n 'ls/.* //p'
+  )
+  case ":$rm_version:" in
+      :$PACKAGE_VERSION:) ;;
+      *) return 1;;
+  esac
+}
+
 require_root_()
 {
   uid_is_privileged_ || skip_ "must be run as root"
   NON_ROOT_USERNAME=${NON_ROOT_USERNAME=nobody}
   NON_ROOT_GROUP=${NON_ROOT_GROUP=$(id -g $NON_ROOT_USERNAME)}
+
+  # When the current test invokes setuidgid, call setuidgid_has_perm_
+  # to check for a common problem.
+  grep '^[ ]*setuidgid' "../$0" \
+    && { setuidgid_has_perm_ \
+           || skip_ "user $NON_ROOT_USERNAME lacks execute permissions"; }
 }
 
 skip_if_root_() { uid_is_privileged_ && skip_ "must be run as non-root"; }