[LTP] [PATCH v4 3/4] tst_test.sh: Fix _tst_cleanup_timer() on set -e

Petr Vorel pvorel@suse.cz
Mon Aug 8 13:37:55 CEST 2022


If test exits on time (i.e. no timeout) kill in _tst_cleanup_timer()
have nothing to kill therefore following wait exits 143.

set -e (or #!/bin/sh -e or set -o errexit) quits on any non-zero exit code,
fix hardens _tst_cleanup_timer() to be able to be used on scripts with it.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
I can use 'if ...; then ; fi' if you prefer:

	if [ "$LTP_COLORIZE_OUTPUT" = "n" -o "$LTP_COLORIZE_OUTPUT" = "0" ]; then
		return 0
	fi

	if [ "$LTP_COLORIZE_OUTPUT" = "y" ] || [ "$LTP_COLORIZE_OUTPUT" = "1" ]; then
		return 1
	fi

...
	if [ "$color" = 1 ]; then
		tst_flag2color "$1"
	fi
	printf "$2"
	if [ "$color" = 1 ]; then
		printf '\033[0m'
	fi


Kind regards,
Petr

 testcases/lib/tst_test.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
index 356af0106..1d2bf06cc 100644
--- a/testcases/lib/tst_test.sh
+++ b/testcases/lib/tst_test.sh
@@ -518,7 +518,7 @@ _tst_cleanup_timer()
 {
 	if [ -n "$_tst_setup_timer_pid" ]; then
 		kill -TERM $_tst_setup_timer_pid 2>/dev/null
-		wait $_tst_setup_timer_pid 2>/dev/null
+		wait $_tst_setup_timer_pid 2>/dev/null || true
 	fi
 }
 
-- 
2.37.1



More information about the ltp mailing list