diff mbox series

[3/4] tst_test.sh: Print warning if slashes in $TMPDIR

Message ID 20240207160628.125908-4-pvorel@suse.cz
State Changes Requested
Headers show
Series Remove double or trailing slashes in TMPDIR in C API | expand

Commit Message

Petr Vorel Feb. 7, 2024, 4:06 p.m. UTC
Further improve changes in 273c49793 to print warning, because C API
started to print warning as well. Previous requirement to not actually
modify $TMPDIR (just to cleanup $TST_TMPDIR) required to rewrite the
code).

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 testcases/lib/tst_test.sh | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
index 0d2fccb95..20bf21660 100644
--- a/testcases/lib/tst_test.sh
+++ b/testcases/lib/tst_test.sh
@@ -666,6 +666,7 @@  tst_run()
 	local _tst_data
 	local _tst_max
 	local _tst_name
+	local _tst_tmpdir
 	local _tst_pattern='[='\''"} \t\/:`$\;|].*'
 	local ret
 
@@ -734,12 +735,18 @@  tst_run()
 
 	if [ "$TST_NEEDS_TMPDIR" = 1 ]; then
 		if [ -z "$TMPDIR" ]; then
-			export TMPDIR="/tmp"
+			_tst_tmpdir="/tmp"
+			export TMPDIR="$_tst_tmpdir"
+		else
+			# remove possible double slashes or trailing slash from TMPDIR
+			_tst_tmpdir=$(echo "$TMPDIR" | sed 's~/\+~/~g; s~/$~~')
+			if [ "$_tst_tmpdir" != "$TMPDIR" ]; then
+				tst_res TINFO "WARNING: Remove double or trailing slashes from TMPDIR," \
+					"please fix your setup to: TMPDIR='$_tst_tmpdir'"
+			fi
 		fi
 
-		TST_TMPDIR=$(mktemp -d "$TMPDIR/LTP_$TST_ID.XXXXXXXXXX")
-		# remove possible trailing slash or double slashes from TMPDIR
-		TST_TMPDIR=$(echo "$TST_TMPDIR" | sed 's~/\+~/~g')
+		TST_TMPDIR=$(mktemp -d "$_tst_tmpdir/LTP_$TST_ID.XXXXXXXXXX")
 
 		chmod 777 "$TST_TMPDIR"