diff mbox

Fix warning of "Usage: _is_block_dev dev"

Message ID 1423745294-20408-1-git-send-email-zhaolei@cn.fujitsu.com (mailing list archive)
State New, archived
Headers show

Commit Message

Zhaolei Feb. 12, 2015, 12:48 p.m. UTC
From: Zhao Lei <zhaolei@cn.fujitsu.com>

_is_block_dev() will show above warning when "$dev" is not exist.
It happened when user hadn't set $SCRATCH_DEV(optional) and check
$TEST_DEV.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
---
 common/rc | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

Comments

Dave Chinner Feb. 15, 2015, 11:04 p.m. UTC | #1
On Thu, Feb 12, 2015 at 08:48:14PM +0800, Zhaolei wrote:
> From: Zhao Lei <zhaolei@cn.fujitsu.com>
> 
> _is_block_dev() will show above warning when "$dev" is not exist.
> It happened when user hadn't set $SCRATCH_DEV(optional) and check
> $TEST_DEV.

_is_block_dev() is used in many places to check whether the block
device exists.  i.e. I'd suggest that _is_block_dev() should return
an empty string to indicate it's not a block device rather than exit
if a null. That means we don't have to execute _is_block_dev() in a
subshell (i.e. via `_is_block_dev ...`) to prevent it from killing
the script that runs it if the block device passed to it is null.

That means we don't have to add checks everywhere it is called, and
we can simplify the calling convention at the same time....

Cheers,

Dave.
diff mbox

Patch

diff --git a/common/rc b/common/rc
index 5377ba0..d9815c7 100644
--- a/common/rc
+++ b/common/rc
@@ -1167,19 +1167,22 @@  _require_test()
 		fi
 		;;
 	*)
-		 if [ -z "$TEST_DEV" -o "`_is_block_dev $TEST_DEV`" = "" ]
-		 then
-		     _notrun "this test requires a valid \$TEST_DEV"
-		 fi
-		 if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
-		 then
-		     _notrun "this test requires a valid \$TEST_DEV"
-		 fi
+		if [ -z "$TEST_DEV" -o "`_is_block_dev $TEST_DEV`" = "" ]
+		then
+		    _notrun "this test requires a valid \$TEST_DEV"
+		fi
+		if [ -n "$SCRATCH_DEV" ]
+		then
+		    if [ "`_is_block_dev $SCRATCH_DEV`" = "`_is_block_dev $TEST_DEV`" ]
+		    then
+			_notrun "this test requires a valid \$TEST_DEV"
+		    fi
+		fi
 		if [ ! -d "$TEST_DIR" ]
 		then
-		     _notrun "this test requires a valid \$TEST_DIR"
+		    _notrun "this test requires a valid \$TEST_DIR"
 		fi
-		 ;;
+		;;
     esac
 
     # mounted?