From 3c2d06d78e1bd2d9298276b44a6ab09cc3b36e5a Mon Sep 17 00:00:00 2001 From: Martin Kletzander Date: Thu, 18 Aug 2022 16:03:01 +0200 Subject: [PATCH] qemu: Do not keep swtpm pidfile around after stopping Just like the socket, remove the pidfile when TPM emulator is being stopped. In order to make this a bit cleaner, try to remove it even if swtpm_ioctl does not exist. https://bugzilla.redhat.com/show_bug.cgi?id=2111301 Signed-off-by: Martin Kletzander Reviewed-by: Michal Privoznik --- src/qemu/qemu_tpm.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c index d0aed7fa2e..20e38ceaa2 100644 --- a/src/qemu/qemu_tpm.c +++ b/src/qemu/qemu_tpm.c @@ -787,26 +787,24 @@ qemuTPMEmulatorStop(const char *swtpmStateDir, g_autofree char *pathname = NULL; g_autofree char *errbuf = NULL; g_autofree char *swtpm_ioctl = virTPMGetSwtpmIoctl(); + g_autofree char *pidfile = qemuTPMEmulatorPidFileBuildPath(swtpmStateDir, + shortName); + if (swtpm_ioctl && + (pathname = qemuTPMEmulatorSocketBuildPath(swtpmStateDir, shortName)) && + virFileExists(pathname)) { - if (!swtpm_ioctl) - return; - - if (!(pathname = qemuTPMEmulatorSocketBuildPath(swtpmStateDir, shortName))) - return; - - if (!virFileExists(pathname)) - return; - - cmd = virCommandNew(swtpm_ioctl); + cmd = virCommandNewArgList(swtpm_ioctl, "--unix", pathname, "-s", NULL); - virCommandAddArgList(cmd, "--unix", pathname, "-s", NULL); + virCommandSetErrorBuffer(cmd, &errbuf); - virCommandSetErrorBuffer(cmd, &errbuf); + ignore_value(virCommandRun(cmd, NULL)); - ignore_value(virCommandRun(cmd, NULL)); + /* clean up the socket */ + unlink(pathname); + } - /* clean up the socket */ - unlink(pathname); + if (pidfile) + virPidFileForceCleanupPath(pidfile); } -- 2.47.2