Skip to contentSkip to conversation

generate_lvm_runfile.sh: Fix bashism

PATCH Superseded Petr Vorel 2 participants 3 messages Aug 3, 2022 – Aug 4, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

PATCH 1/1 generate_lvm_runfile.sh: Fix bashism

ERR is not on dash (tested on 0.5.11).

---
 testcases/misc/lvm/generate_lvm_runfile.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/misc/lvm/generate_lvm_runfile.sh +1 -1
index 72b286a69..5bf5d91d6 100755
@@ -13,7 +13,7 @@ LVM_TMPDIR="$LVM_DIR/ltp/growfiles"
 
 generate_runfile()
 {
-	trap 'tst_brk TBROK "Cannot create LVM runfile"' ERR
+	trap '[ $? -eq 0 ] && exit 0 || tst_brk TBROK "Cannot create LVM runfile"' EXIT
 	INFILE="$LTPROOT/testcases/data/lvm/runfile.tpl"
 	OUTFILE="$LTPROOT/runtest/lvm.local"
 	FS_LIST=`tst_supported_fs`
Signature · 5 lines
2.37.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi,
trap ... EXIT cannot be used to emulate trap ... ERR. The latter behaves as if every command/pipeline in the script (except conditions) were wrapped in ROD. So trap ... ERR will trigger exit on any failure, while trap ... EXIT will let the script continue after all errors and then check exit code of only the very last command. That's not what we want here.

Quoted 20 lines · Petr Vorel

ERR is not on dash (tested on 0.5.11).

---
 testcases/misc/lvm/generate_lvm_runfile.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/misc/lvm/generate_lvm_runfile.sh +1 -1
index 72b286a69..5bf5d91d6 100755
@@ -13,7 +13,7 @@ LVM_TMPDIR="$LVM_DIR/ltp/growfiles"
 
 generate_runfile()
 {
-	trap 'tst_brk TBROK "Cannot create LVM runfile"' ERR
+	trap '[ $? -eq 0 ] && exit 0 || tst_brk TBROK "Cannot create LVM runfile"' EXIT
 	INFILE="$LTPROOT/testcases/data/lvm/runfile.tpl"
 	OUTFILE="$LTPROOT/runtest/lvm.local"
 	FS_LIST=`tst_supported_fs`
Signature · 7 lines
Martin Doucha   [email protected]
QA Engineer for Software Maintenance
SUSE LINUX, s.r.o.
CORSO IIa
Krizikova 148/34
186 00 Prague 8
Czech Republic
author
#2 lore raw

Hi Martin,

Quoted 4 lines

Hi,
trap ... EXIT cannot be used to emulate trap ... ERR. The latter behaves as if every command/pipeline in the script (except conditions) were wrapped in ROD. So trap ... ERR will trigger exit on any failure,

Ah, thx for info. OK, we also need to add set -e (or #!/bin/sh -e). Because using ERR would require to change shebang to #!/bin/bash.

Kind regards,
Petr

Quoted 25 lines

while trap ... EXIT will let the script continue after all errors and then check exit code of only the very last command. That's not what we want here.

Quoted 20 lines · Petr Vorel

ERR is not on dash (tested on 0.5.11).

---
 testcases/misc/lvm/generate_lvm_runfile.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/misc/lvm/generate_lvm_runfile.sh +1 -1
index 72b286a69..5bf5d91d6 100755
@@ -13,7 +13,7 @@ LVM_TMPDIR="$LVM_DIR/ltp/growfiles"
 
 generate_runfile()
 {
-	trap 'tst_brk TBROK "Cannot create LVM runfile"' ERR
+	trap '[ $? -eq 0 ] && exit 0 || tst_brk TBROK "Cannot create LVM runfile"' EXIT
 	INFILE="$LTPROOT/testcases/data/lvm/runfile.tpl"
 	OUTFILE="$LTPROOT/runtest/lvm.local"
 	FS_LIST=`tst_supported_fs`