[LTP] [PATCH 2/3] ima_setup.sh: Use TST_MOUNT_DEVICE

Petr Vorel pvorel@suse.cz
Fri Sep 23 12:55:53 CEST 2022


Use TST_MOUNT_DEVICE instead of mounting loop device manually.

Also move unset TST_NEEDS_DEVICE before loading tst_test.sh, as it's not
a good idea to modify the API variables after loading tst_test.sh.

NOTE: removed cd before umount as it has been resolved in the shell API
(tst_test.sh) in the previous commit.

Fixes: 04021637f ("tst_test.sh: Cleanup getopts usage")

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 .../security/integrity/ima/tests/ima_setup.sh | 29 +++++--------------
 1 file changed, 8 insertions(+), 21 deletions(-)

diff --git a/testcases/kernel/security/integrity/ima/tests/ima_setup.sh b/testcases/kernel/security/integrity/ima/tests/ima_setup.sh
index a626aae44..055701aff 100644
--- a/testcases/kernel/security/integrity/ima/tests/ima_setup.sh
+++ b/testcases/kernel/security/integrity/ima/tests/ima_setup.sh
@@ -10,8 +10,9 @@ TST_SETUP="ima_setup"
 TST_CLEANUP_CALLER="$TST_CLEANUP"
 TST_CLEANUP="ima_cleanup"
 TST_NEEDS_ROOT=1
+TST_MOUNT_DEVICE=1
 
-# TST_NEEDS_DEVICE can be unset, therefore specify explicitly
+# TST_MOUNT_DEVICE can be unset, therefore specify explicitly
 TST_NEEDS_TMPDIR=1
 
 SYSFS="/sys"
@@ -142,15 +143,6 @@ mount_helper()
 	echo $default_dir
 }
 
-mount_loop_device()
-{
-	local ret
-
-	tst_mkfs
-	tst_mount
-	cd $TST_MNTPOINT
-}
-
 print_ima_config()
 {
 	local config="${KCONFIG_PATH:-/boot/config-$(uname -r)}"
@@ -183,9 +175,9 @@ ima_setup()
 
 	print_ima_config
 
-	if [ "$TST_NEEDS_DEVICE" = 1 ]; then
+	if [ "$TST_MOUNT_DEVICE" = 1 ]; then
 		tst_res TINFO "\$TMPDIR is on tmpfs => run on loop device"
-		mount_loop_device
+		cd "$TST_MNTPOINT"
 	fi
 
 	[ -n "$TST_SETUP_CALLER" ] && $TST_SETUP_CALLER
@@ -200,11 +192,6 @@ ima_cleanup()
 	for dir in $UMOUNT; do
 		umount $dir
 	done
-
-	if [ "$TST_NEEDS_DEVICE" = 1 ]; then
-		cd $TST_TMPDIR
-		tst_umount
-	fi
 }
 
 set_digest_index()
@@ -348,10 +335,10 @@ require_evmctl()
 	fi
 }
 
-. tst_test.sh
-
 # loop device is needed to use only for tmpfs
 TMPDIR="${TMPDIR:-/tmp}"
-if [ "$(df -T $TMPDIR | tail -1 | awk '{print $2}')" != "tmpfs" -a -n "$TST_NEEDS_DEVICE" ]; then
-	unset TST_NEEDS_DEVICE
+if [ "$(df -T $TMPDIR | tail -1 | awk '{print $2}')" != "tmpfs" -a -n "$TST_MOUNT_DEVICE" ]; then
+	unset TST_MOUNT_DEVICE
 fi
+
+. tst_test.sh
-- 
2.37.3



More information about the ltp mailing list