[kvm-unit-tests PATCH 2/9] arch-run: Clean up temporary files properly

Nicholas Piggin
2023-12-22T13:51:20Z

Migration files weren't being removed when tests were interrupted.
This improves the situation.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
scripts/arch-run.bash | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash
index d0864360..f22ead6f 100644
--- a/scripts/arch-run.bash
+++ b/scripts/arch-run.bash
@@ -134,12 +134,14 @@ run_migration ()
qmp1=$(mktemp -u -t mig-helper-qmp1.XXXXXXXXXX)
qmp2=$(mktemp -u -t mig-helper-qmp2.XXXXXXXXXX)
fifo=$(mktemp -u -t mig-helper-fifo.XXXXXXXXXX)
+
+ # race here between file creation and trap
+ trap "trap - TERM ; kill 0 ; exit 2" INT TERM
+ trap "rm -f ${migout1} ${migsock} ${qmp1} ${qmp2} ${fifo}" RETURN EXIT
+
qmpout1=/dev/null
qmpout2=/dev/null

- trap 'kill 0; exit 2' INT TERM
- trap 'rm -f ${migout1} ${migsock} ${qmp1} ${qmp2} ${fifo}' RETURN EXIT
-
eval "$@" -chardev socket,id=mon1,path=${qmp1},server=on,wait=off \
-mon chardev=mon1,mode=control | tee ${migout1} &
live_pid=`jobs -l %+ | grep "eval" | awk '{print$2}'`
@@ -211,8 +213,8 @@ run_panic ()

qmp=$(mktemp -u -t panic-qmp.XXXXXXXXXX)

- trap 'kill 0; exit 2' INT TERM
- trap 'rm -f ${qmp}' RETURN EXIT
+ trap "trap - TERM ; kill 0 ; exit 2" INT TERM
+ trap "rm -f ${qmp}" RETURN EXIT

# start VM stopped so we don't miss any events
eval "$@" -chardev socket,id=mon1,path=${qmp},server=on,wait=off \
--
2.42.0