From 8149250f7e58e492a0248251eafaf68873984ba1 Mon Sep 17 00:00:00 2001 From: Cedric Hombourger Date: Tue, 16 Jan 2024 13:12:40 +0100 Subject: [PATCH] chore(power/qemu): simplify shutdown Attempt to write to the FIFO for QEMU's monitor may block. Simplify shutting down of qemu/kvm by removing the use of the "quit" command and immediately send SIGTERM. Signed-off-by: Cedric Hombourger --- mtda/power/qemu.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/mtda/power/qemu.py b/mtda/power/qemu.py index 37badfd9..6f79d434 100644 --- a/mtda/power/qemu.py +++ b/mtda/power/qemu.py @@ -269,18 +269,12 @@ def start(self): "({0})".format(result)) return False - def kill(self, name, pid, wait_before_kill=True, timeout=3): + def kill(self, name, pid, timeout=3): tries = timeout - while wait_before_kill and tries > 0 and psutil.pid_exists(pid): - self.mtda.debug(2, "waiting {0} more seconds for {1} " - "[{2}] to terminate".format(timeout, name, pid)) - time.sleep(1) - tries = tries - 1 if psutil.pid_exists(pid): self.mtda.debug(2, "terminating {0} " "[{1}] using SIGTERM".format(name, pid)) os.kill(pid, signal.SIGTERM) - tries = timeout while tries > 0 and psutil.pid_exists(pid): time.sleep(1) tries = tries - 1 @@ -297,20 +291,17 @@ def stop(self): result = True if self.pidOfQemu is not None: - - with open("/tmp/qemu-mtda.in", "w") as f: - f.write("quit\n") result = self.kill("qemu", self.pidOfQemu) if result: self.pidOfQemu = None if self.pidOfSwTpm is not None: - result = self.kill("swtpm", self.pidOfSwTpm, False) + result = self.kill("swtpm", self.pidOfSwTpm) if result: self.pidOfSwTpm = None if self.pidOfWebsockify is not None: - result = self.kill("websockify", self.pidOfWebsockify, False) + result = self.kill("websockify", self.pidOfWebsockify) if result: self.pidOfWebsockify = None