OSDN Git Service

tests: sanitize PATH; do not discard mkswap output
authorJim Meyering <meyering@redhat.com>
Sun, 19 Feb 2012 14:31:58 +0000 (15:31 +0100)
committerJim Meyering <meyering@redhat.com>
Tue, 21 Feb 2012 08:22:03 +0000 (09:22 +0100)
* tests/init.cfg (sanitize_path_): New function, from coreutils.
Use it.
* tests/t9050-partition-table-types.sh: Do not discard mkswap output
and diagnostics.  This test would fail (e.g., on OpenSUSE 12.1), when
run with PATH not including /sbin.  Reported by Bruno Haible.

tests/init.cfg
tests/t9050-partition-table-types.sh

index 6072acd..24b10bc 100644 (file)
@@ -25,6 +25,41 @@ require_512_byte_sector_size_()
   test $sector_size_ = 512 || skip_ 'FS test with sector size != 512'
 }
 
+# Having an unsearchable directory in PATH causes execve to fail with EACCES
+# when applied to an unresolvable program name, contrary to the desired ENOENT.
+# Avoid the problem by rewriting PATH to exclude unsearchable directories.
+# Also, if PATH lacks /sbin and/or /usr/sbin, append it/them.
+sanitize_path_()
+{
+  # FIXME: remove double quotes around $IFS when all tests use init.sh.
+  # They constitute a work-around for a bug in FreeBSD 8.1's /bin/sh.
+  local saved_IFS="$IFS"
+    IFS=:
+    set -- $PATH
+  IFS=$saved_IFS
+
+  local d d1
+  local colon=
+  local new_path=
+  for d in "$@"; do
+    test -z "$d" && d1=. || d1=$d
+    if ls -d "$d1/." > /dev/null 2>&1; then
+      new_path="$new_path$colon$d"
+      colon=':'
+    fi
+  done
+
+  for d in /sbin /usr/sbin ; do
+    case ":$new_path:" in
+      *:$d:*) ;;
+      *) new_path="$new_path:$d" ;;
+    esac
+  done
+
+  PATH=$new_path
+  export PATH
+}
+
 require_udevadm_settle_()
 {
   udevadm --help > /dev/null \
@@ -90,5 +125,7 @@ require_partitionable_loop_device_()
   esac
 }
 
+sanitize_path_
+
 . "$abs_top_srcdir/tests/t-lib-helpers.sh"
 . "$abs_top_srcdir/tests/t-local.sh"
index 563b2e8..04dc5c6 100755 (executable)
@@ -41,7 +41,7 @@ dd if=/dev/null of=f bs=1 seek=30M || framework_failure_
 for i in $types; do
   for j in $types; do
     echo $i:$j
-    case $i in mkswap) mkswap f >/dev/null 2>&1 || fail=1;;
+    case $i in mkswap) mkswap f || fail=1;;
       *) parted -s f mklabel $i || fail=1;; esac
     case $j in mkswap) continue;; esac
     parted -s f mklabel $j || fail=1