[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] tests: avoid subtle shell semantics bug
From: |
Jim Meyering |
Subject: |
[PATCH] tests: avoid subtle shell semantics bug |
Date: |
Tue, 10 May 2011 10:20:40 +0200 |
This bug (probably coupled with a change in F15's bash to make it
POSIX 2008 compliant) made it so several root-only tests were
mistakenly skipped.
>From ce5941fb9b6cbdc2030a053c491d3b7d8c00d830 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Mon, 9 May 2011 22:00:57 +0200
Subject: [PATCH] tests: avoid subtle shell semantics bug
This bug was causing some root-only tests to be mistakenly skipped.
This bash command will always exit successfully,
i.e., the "return 1" will never happen:
bash -c 'f(){ local f=$(false)||return 1; return 0; }; f'
That's because the assignment always succeeds, and that success
is what determines the return value, not the $(...) command.
This is very counter-intuitive, sigh.
The work-around is to separate the declaration and assignment, as in
local f; f=$(...) || ...
* tests/t-local.sh (new_sdX_): Do that.
(gpt_corrupt_primary_table_): Likewise.
---
tests/t-local.sh | 7 ++++---
1 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/tests/t-local.sh b/tests/t-local.sh
index 8e2ef07..b9b8b28 100644
--- a/tests/t-local.sh
+++ b/tests/t-local.sh
@@ -74,7 +74,7 @@ scsi_debug_acquire_lock_()
# Otherwise, return 1.
new_sdX_()
{
- local m=$(grep -lw scsi_debug /sys/block/sd*/device/model) || return 1
+ local m; m=$(grep -lw scsi_debug /sys/block/sd*/device/model) || return 1
# Remove the /sys/block/ prefix, and then the /device/model suffix.
m=${m#/sys/block/}
@@ -113,7 +113,7 @@ scsi_debug_setup_()
case $new_dev in
sd[a-z]) ;;
sd[a-z][a-z]) ;;
- *) return 1 ;;
+ *) warn_ $ME_ unexpected device name: $new_dev; return 1 ;;
esac
local t=/dev/$new_dev
wait_for_dev_to_appear_ $t
@@ -162,7 +162,8 @@ gpt_corrupt_primary_table_()
case $ss in *[^0-9]*) echo "$0: invalid sector size: $ss">&2; return 1;; esac
# get the first byte of the name
- local orig_pte_name_byte=$(peek_ $dev $(gpt1_pte_name_offset_ $ss)) ||
return 1
+ local orig_pte_name_byte
+ orig_pte_name_byte=$(peek_ $dev $(gpt1_pte_name_offset_ $ss)) || return 1
local new_byte
test x"$orig_pte_name_byte" = xA && new_byte=B || new_byte=A
--
1.7.5.1.354.g761178
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] tests: avoid subtle shell semantics bug,
Jim Meyering <=