[PATCH] ldd pipefail check on non-bash shells

Pete Eberlein eberlein@us.ibm.com
Sat Jan 20 01:24:00 GMT 2007


Hello all,
     I've recently ran into an issue when using 'ldd' with shells other
than bash.  The problem is that the behavior of 'set -o <unknown>'
varies amongst shell implementations.  I'm not sure what official posix
shell behavior should be.

     Running:
     $ sh -c 'if set -o XX; then echo yes ; else echo no ; fi ; echo END'
     When 'sh' is one of dash, ash, busybox's ash, or the /bin/sh on AIX
5.3, the shell will print error and immediately exit .  For example:

     $ ash -c 'if set -o XX; then echo yes ; else echo no ; fi ; echo END'
     set: 1: Illegal option -o XX

Notice, there is no 'END' printed.  But,

     $ bash -c 'if set -o XX ; then echo yes ; else echo no ; fi ; echo END'
     bash: line 0: set: XX: invalid option name
     no
     END

     ldd currently relies on the second behavior.
     The change that I have below is to not use 'set -o pipefail' to check
for pipefail support, but rather to run 'set -o' and search the output
for 'pipefail'.
     This change worked on all the shells I tested.

-- 
Pete Eberlein  503-578-3522
IBM Linux Technology Center
Linux on Power Toolchain



2007-01-19  Pete Eberlein  <eberlein@us.ibm.com>

	* elf/ldd.bash.in: The pipefail check is more robust when using
	non-bash shells.


--- glibc-2.4/elf/ldd.bash.in.orig 2006-11-21 22:15:23.000000000 +0000
+++ glibc-2.4/elf/ldd.bash.in 2007-01-15 18:30:32.287310306 +0000
@@ -119,7 +119,7 @@
   # environments where the executed program might not have permissions
   # to write to the console/tty.  But only bash 3.x supports the pipefail
   # option, and we don't bother to handle the case for older bash
   # versions.
-if set -o pipefail 2> /dev/null; then
+if x=`set -o` && test "$x" != "${x#*pipefail}" && set -o pipefail ;
then
     try_trace() {
       eval $add_env '"$@"' | cat
     }



More information about the Libc-alpha mailing list