From 73fd9bf5580d8b7d1f61b2e90dfd352355028f4a Mon Sep 17 00:00:00 2001 From: Po-Hsu Lin Date: Wed, 19 Oct 2022 14:17:29 +0800 Subject: [PATCH] tests: lxc-test-checkpoint-restore: use trap to do cleanup This test will fail on Jammy 5.15, and because of the "set -e" it will never go through the lxc-stop and lxc-destroy code in the end of this script. Thus the lxc-test-criu container will not be removed. Compose a cleanup() and use TRAP to solve this problem. Signed-off-by: Po-Hsu Lin --- src/tests/lxc-test-checkpoint-restore | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/tests/lxc-test-checkpoint-restore b/src/tests/lxc-test-checkpoint-restore index 5aee0a427..9498c126e 100755 --- a/src/tests/lxc-test-checkpoint-restore +++ b/src/tests/lxc-test-checkpoint-restore @@ -10,6 +10,12 @@ FAIL() { exit 1 } +cleanup() { + set +e + lxc-stop -n $name -k + lxc-destroy -f -n $name +} + if [ "$(id -u)" != "0" ]; then echo "ERROR: Must run as root." exit 1 @@ -27,6 +33,7 @@ if verlte "$criu_version" "1.3.1"; then fi name=lxc-test-criu +trap cleanup EXIT HUP INT TERM lxc-create -t busybox -n $name || FAIL "creating container" cat >> "$(lxc-config lxc.lxcpath)/$name/config" <