diff options
author | Luca Boccassi <luca.boccassi@microsoft.com> | 2021-02-16 23:47:34 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2021-02-17 18:55:05 +0100 |
commit | 0761da386a6cb0ced3721f2dee123fd983c71178 (patch) | |
tree | 820db6fecf6c47e976aa3fa0c202772820797cb5 /test | |
parent | 50fc7d7036ad9b36840896a67ba9ed7bb4c44016 (diff) | |
download | systemd-0761da386a6cb0ced3721f2dee123fd983c71178.tar.gz |
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.
Diffstat (limited to 'test')
-rw-r--r-- | test/test-functions | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/test/test-functions b/test/test-functions index 7b8a1a3207..39df122ef2 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" - ) </dev/null >"$TESTLOG" 2>&1 || ret=$? + # Do not use a subshell, otherwise cleanup variables (LOOPDEV) will be lost + # and loop devices will leak + test_setup </dev/null >"$TESTLOG" 2>&1 || ret=$? + if [ $ret -eq 0 ]; then + test_setup_cleanup </dev/null >>"$TESTLOG" 2>&1 || ret=$? + fi + if [ $ret -eq 0 ]; then + test_run "$2" </dev/null >>"$TESTLOG" 2>&1 || ret=$? + fi test_cleanup if [ $ret -eq 0 ]; then rm "$TESTLOG" |