From: Luca Boccassi Date: Tue, 16 Feb 2021 23:47:34 +0000 (+0000) Subject: test: avoid leaking open loop devices X-Git-Tag: v248-rc1~78 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0761da386a6cb0ced3721f2dee123fd983c71178;p=thirdparty%2Fsystemd.git test: avoid leaking open loop devices When a subshell is used ('make' or 'make all') the LOOPDEV environment variable, which is used to store the opened loop device, is lost. So the cleanup on trap/exit doesn't do anything, and the loop device used to mount the test image is left around. Avoid using a subshell to fix the issue. --- diff --git a/test/test-functions b/test/test-functions index 7b8a1a32077..39df122ef23 100644 --- a/test/test-functions +++ b/test/test-functions @@ -2320,11 +2320,15 @@ do_test() { --all) ret=0 echo -n "${testname}: $TEST_DESCRIPTION " - ( - test_setup - test_setup_cleanup - test_run "$2" - ) "$TESTLOG" 2>&1 || ret=$? + # Do not use a subshell, otherwise cleanup variables (LOOPDEV) will be lost + # and loop devices will leak + test_setup "$TESTLOG" 2>&1 || ret=$? + if [ $ret -eq 0 ]; then + test_setup_cleanup >"$TESTLOG" 2>&1 || ret=$? + fi + if [ $ret -eq 0 ]; then + test_run "$2" >"$TESTLOG" 2>&1 || ret=$? + fi test_cleanup if [ $ret -eq 0 ]; then rm "$TESTLOG"