From: Nicholas Nethercote Date: Thu, 30 Oct 2003 09:37:47 +0000 (+0000) Subject: Previously, if the command given to Valgrind didn't exist, the 'stat -c' X-Git-Tag: svn/VALGRIND_2_1_0~100 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=dadd326e8748b08d859eaf0343eb1284bbfc7cb5;p=thirdparty%2Fvalgrind.git Previously, if the command given to Valgrind didn't exist, the 'stat -c' suid/sgid test failed, and the startup script aborted with an ugly message. I've changed it so that it first checks that the program exists in the user's path (as determined by 'which'), and aborts if not. This was quite fiddly to get right; yell if I've broken anything. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1967 --- diff --git a/coregrind/valgrind.in b/coregrind/valgrind.in index 4b3eb37388..a763f4bae0 100755 --- a/coregrind/valgrind.in +++ b/coregrind/valgrind.in @@ -109,28 +109,40 @@ if getconf GNU_LIBPTHREAD_VERSION | grep -qi NPTL 2>/dev/null; then export LD_ASSUME_KERNEL fi -which_prog="`which $1`" +# Check that the program looks ok +is_prog=0 -# Ensure the program isn't statically linked. if [ $# != 0 ] ; then - case `file "$which_prog"` in - *"statically linked"*) - echo "\`$which_prog' is statically linked" - echo "Valgrind only works on dynamically linked executables; your" - echo "program must rely on at least one shared object for Valgrind" - echo "to work with it. Read FAQ #5 for more information." - exit 1 ;; - esac -fi -# Ensure that there is no suid or sgid flag -if [ `stat -c %a "$which_prog"` -gt 2000 ] ; then - echo "\`$which_prog' is suid/sgid." - echo "Valgrind can't handle these executables, as it" - echo "requires the LD_PRELOAD feature in order to work." - echo "" - echo "Remove those flags and try again." - exit 1 + # Ensure the program exists. Ignore any error messages from 'which'. + which_prog=`which $1 2> /dev/null` + if [ z$which_prog = z ] ; then + echo "'$1' not found in \$PATH, aborting." + exit + fi + + # Ensure the program isn't statically linked. + if [ $# != 0 ] ; then + case `file "$which_prog"` in + *"statically linked"*) + echo "\`$which_prog' is statically linked" + echo "Valgrind only works on dynamically linked executables; your" + echo "program must rely on at least one shared object for Valgrind" + echo "to work with it. Read FAQ #5 for more information." + exit 1 ;; + esac + fi + + # Ensure that there is no suid or sgid flag + if [ `stat -c %a "$which_prog"` -gt 2000 ] ; then + echo "\`$which_prog' is suid/sgid." + echo "Valgrind can't handle these executables, as it" + echo "requires the LD_PRELOAD feature in order to work." + echo "" + echo "Remove those flags and try again." + exit 1 + fi + is_prog=1 fi # A bit subtle. The LD_PRELOAD added entry must be absolute @@ -149,13 +161,14 @@ export LD_PRELOAD #LD_DEBUG=symbols #export LD_DEBUG -# If no command given, act like -h was given so vg_main.c prints out -# the usage string. And pass to 'exec' tha name of any program -- it doesn't -# matter which -- because it won't be run anyway (we use 'true'). -if [ $# != 0 ] ; then +# Actually run the program, under Valgrind's control +if [ $is_prog = 1 ] ; then exec "$@" else - VG_ARGS="$VG_ARGS -h" + # If no command given, act like -h was given so vg_main.c prints out the + # usage string. And pass to 'exec' the name of any program -- it doesn't + # matter which -- because it won't be run anyway (we use 'true'). + VG_ARGS="$VG_ARGS -h" exec true fi