bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] init.sh: avoid Solaris 10 /bin/sh portability problem


From: Jim Meyering
Subject: [PATCH] init.sh: avoid Solaris 10 /bin/sh portability problem
Date: Tue, 08 Dec 2009 21:24:55 +0100

In preparing for coreutils-8.2, I noticed that test-xalloc-die.sh
would fail on Solaris 10 because the PATH-prepending part of
init.sh's setup_ function was not being run.
That was due to a difference in how Sun's /bin/sh works.
Here's the fix I've pushed:


>From 5aad650f4e093269e4184cb150f735f6999784d6 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Tue, 8 Dec 2009 20:37:50 +0100
Subject: [PATCH] init.sh: avoid Solaris 10 /bin/sh portability problem

Solaris 10's /bin/sh does not pass '.' arguments 2..N to the
sourced script:
  $ printf 'echo "$@"\n' > f; /bin/sh -c '. ./f bar'
  $ printf 'echo "$@"\n' > f;    bash -c '. ./f bar'
  bar
tests/init.sh relied on that, accepting a --set-path=DIR argument,
and two tests used that idiom.
* tests/init.sh: Update suggested usage comments.
(path_prepend_): New function, to be used in place of
the --src-path=DIR option.
Disallow empty strings and strings containing ":".
(setup_): Move PATH-prepending code into path_prepend_.
* tests/test-pread.sh: Adapt to new usage.
* tests/test-xalloc-die.sh: Likewise.
---
 ChangeLog                |   17 +++++++++++++++++
 tests/init.sh            |   42 ++++++++++++++++++++++--------------------
 tests/test-pread.sh      |    3 +--
 tests/test-xalloc-die.sh |    2 +-
 4 files changed, 41 insertions(+), 23 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 1ae4d63..0afec2e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2009-12-08  Jim Meyering  <address@hidden>
+
+       init.sh: avoid Solaris 10 /bin/sh portability problem
+       Solaris 10's /bin/sh does not pass '.' arguments 2.. to the
+       sourced script:
+         $ printf 'echo "$@"\n' > f; /bin/sh -c '. ./f bar'
+         $ printf 'echo "$@"\n' > f; /bin/bash -c '. ./f bar'
+         bar
+       tests/init.sh relied on that, accepting a --set-path=DIR argument,
+       and two tests used that idiom.
+       * tests/init.sh: Update suggested usage comments.
+       (path_prepend_): New function, to be used in place
+       of the --src-path=DIR option.
+       (setup_): Move PATH-prepending code into path_prepend_.
+       * tests/test-pread.sh: Adapt to new usage.
+       * tests/test-xalloc-die.sh: Likewise.
+
 2009-12-08  Simon Josefsson  <address@hidden>

        * doc/gnulib.texi (Glibc pty.h): Add.
diff --git a/tests/init.sh b/tests/init.sh
index 368da6d..cc02487 100644
--- a/tests/init.sh
+++ b/tests/init.sh
@@ -22,7 +22,7 @@
 #
 #   #!/bin/sh
 #   : ${srcdir=.}
-#   . "$srcdir/init.sh" --set-path=.
+#   . "$srcdir/init.sh"; path_prepend_ .
 #   Execute some commands.
 #   Note that these commands are executed in a subdirectory, therefore you
 #   need to prepend "../" to relative filenames in the build directory.
@@ -47,7 +47,7 @@
 #      Makefile:
 #   $ export srcdir=../../tests # this is an example
 #   3. Execute the commands from the test, copy&pasting them one by one:
-#   $ . "$srcdir/init.sh" --set-path=.
+#   $ . "$srcdir/init.sh"; path_prepend_ .
 #   ...
 #   4. Finally
 #   $ exit
@@ -92,28 +92,30 @@ remove_tmp_()
   exit $__st
 }

-setup_()
+# Use this function to prepend to PATH an absolute name for each
+# specified, possibly-$initial_cwd_relative, directory.
+path_prepend_()
 {
-  test "$VERBOSE" = yes && set -x
-
-  # Honor one or more --set-path=. options (i.e., or --set-path=../src).
-  # Use this option to prepend to PATH an absolute name for the
-  # specified, possibly-relative, directory.
   while test $# != 0; do
-    case $1 in
-      --set-path=*)
-        path_dir_=${1#--set-path=}
-        test -z "$path_dir_" && fail_ "missing argument to --set-path="
-        abs_path_dir_=`cd "$path_dir_" && echo "$PWD" || exit 1` \
-            || fail_ "invalid path dir: $path_dir"
-        PATH="$abs_path_dir_:$PATH"
-        export PATH
-        shift
-        ;;
-      *) fail_ "unrecognized option: $1"
-        ;;
+    path_dir_=$1
+    case $path_dir_ in
+      '') fail_ "invalid path dir: '$1'";;
+      /*) abs_path_dir_=$path_dir_;;
+      *) abs_path_dir_=`cd "$initial_cwd_/$path_dir_" && echo "$PWD"` \
+           || fail_ "invalid path dir: $path_dir_";;
     esac
+    case $abs_path_dir_ in
+      *:*) fail_ "invalid path dir: '$abs_path_dir_'";;
+    esac
+    PATH="$abs_path_dir_:$PATH"
+    shift
   done
+  export PATH
+}
+
+setup_()
+{
+  test "$VERBOSE" = yes && set -x

   initial_cwd_=$PWD
   ME_=`expr "./$0" : '.*/\(.*\)$'`
diff --git a/tests/test-pread.sh b/tests/test-pread.sh
index 59f8536..cd4c04d 100755
--- a/tests/test-pread.sh
+++ b/tests/test-pread.sh
@@ -1,6 +1,5 @@
 #!/bin/sh
-: ${srcdir=.}
-. "$srcdir/init.sh" --set-path=.
+. "${srcdir=.}/init.sh"; path_prepend_ .

 fail=0
 : | test-pread || fail=1
diff --git a/tests/test-xalloc-die.sh b/tests/test-xalloc-die.sh
index 28cce6d..4188a04 100755
--- a/tests/test-xalloc-die.sh
+++ b/tests/test-xalloc-die.sh
@@ -16,7 +16,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.

-. "${srcdir=.}/init.sh" --set-path=.
+. "${srcdir=.}/init.sh"; path_prepend_ .

 test-xalloc-die 2> err > out
 case $? in
--
1.6.6.rc1.307.g3c2c0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]