From patchwork Tue Apr 14 21:45:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dave Chinner X-Patchwork-Id: 6218301 Return-Path: X-Original-To: patchwork-fstests@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 26CA0BF4A6 for ; Tue, 14 Apr 2015 21:45:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 316DA2021F for ; Tue, 14 Apr 2015 21:45:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2989520120 for ; Tue, 14 Apr 2015 21:45:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753893AbbDNVpP (ORCPT ); Tue, 14 Apr 2015 17:45:15 -0400 Received: from ipmail04.adl6.internode.on.net ([150.101.137.141]:4711 "EHLO ipmail04.adl6.internode.on.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753927AbbDNVpP (ORCPT ); Tue, 14 Apr 2015 17:45:15 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2DBDAC5iS1VPM+HLHlcgwyBLoJHToMtrU4BAQEBAQEGmSECAgEBAoFJTQEBAQEBAQcBAQEBODuEHwEBAQQjBAsBIyMQCAECFQMCAgUhAgIPBSUDBxoTiCmXTZ0CliQBAQgCAR8YgQmEb4UbhHwHgmiBRQWbHoEeij6FRINNhCMsMYJDAQEB Received: from ppp121-44-135-207.lns20.syd7.internode.on.net (HELO dastard) ([121.44.135.207]) by ipmail04.adl6.internode.on.net with ESMTP; 15 Apr 2015 07:15:13 +0930 Received: from dave by dastard with local (Exim 4.80) (envelope-from ) id 1Yi8ds-0002Si-IA; Wed, 15 Apr 2015 07:45:12 +1000 Date: Wed, 15 Apr 2015 07:45:12 +1000 From: Dave Chinner To: Zhaolei Cc: fstests@vger.kernel.org Subject: Re: [PATCH v2] Fix caller's argument for _require_command() Message-ID: <20150414214512.GR13731@dastard> References: <188af9eed150e2f7efb04b5d634a14ca50fdd694.1428899527.git.zhaolei@cn.fujitsu.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <188af9eed150e2f7efb04b5d634a14ca50fdd694.1428899527.git.zhaolei@cn.fujitsu.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Mon, Apr 13, 2015 at 12:32:43PM +0800, Zhaolei wrote: > From: Zhao Lei > > _require_command() only accept 2 arguments, first one is pure command, > and second one is name for error message. > > But some caller misused this function, for example, > DEFRAG_PROG="$BTRFS_UTIL_PROG filesystem defragment" > _require_command $DEFRAG_PROG defragment > In above code, _require_command get 4 arguments, the caller's > second argument is never used, and the second field of first > argument is treat as "error message" in _require_command. > > We fixed above case by adding quotes to _require_command()'s > arguments, it fixed most test case, but introduced a new bug, > in above case, "btrfs filesystem defragment" is not a command, > and always failed in _require_command(), it caused some testcase > not work, as btrfs/005. > > This patch fixed above caller. > > Changelog v1->v2: > 1: Add detail description, suggested by: > Lukáš Czerner > 2: Add missed Reported-by. > 3: Make $XFSDUMP_PROG always be a pure command, to avoid special > handling for it. Having to change xfsdump checks means this is still the wrong fix. _require_command should simply handle multi-part command strings. Does the following patch fix your problems? -Dave. diff --git a/common/rc b/common/rc index ca8da7f..6ea107e 100644 --- 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 []" + 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