]> git.apps.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
common: _require_command needs to handle parameters
authorDave Chinner <dchinner@redhat.com>
Mon, 4 May 2015 06:48:05 +0000 (16:48 +1000)
committerDave Chinner <david@fromorbit.com>
Mon, 4 May 2015 06:48:05 +0000 (16:48 +1000)
_require_command fails when a parameter based command is passed to
it, such as "xfs_io -F" or "btrfs filesystem defrag" as the command
string does not point at a binary.  Rather than hacking at all the
callers and limiting what we can do with $*_PROGS variables, just
make _require_command handle this case sanely.

Change _require_command to check for one or two variables passed to
it and to fail if none or more than 2 parameters are passed. This
will catch most cases where unquoted parameter-based commands are
passed. Further, for the command variable, the executable we need to
check for is always going to be the first token in the variable.
Hence we can simply ignore everything after the first token for the
purposes of existence and executable checks on the command.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
common/rc

index ca8da7f34fbcdb3d17502ca3d72041a06f25eca6..6ea107e1efea33e7112952882b070574daaf6b9d 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -1286,10 +1286,22 @@ _require_realtime()
 # this test requires that a specified command (executable) exists
 # $1 - command, $2 - name for error message
 #
+# Note: the command string might have parameters, so strip them before checking
+# whether it is executable.
 _require_command()
 {
-    [ -n "$1" ] && _cmd="$1" || _cmd="$2"
-    [ -n "$1" -a -x "$1" ] || _notrun "$_cmd utility required, skipped this test"
+       if [ $# -eq 2 ]; then
+               _name="$2"
+       elif [ $# -eq 1 ]; then
+               _name="$1"
+       else
+               _fail "usage: _require_command <command> [<name>]"
+       fi
+
+       _command=`echo "$1" | awk '{ print $1 }'`
+       if [ ! -x $command ]; then
+               _notrun "$_name utility required, skipped this test"
+       fi
 }
 
 # this test requires the device to be valid block device