On 8/18/22 16:20, Martin Kletzander wrote:
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.
Signed-off-by: Martin Kletzander <mkletzan(a)redhat.com>
---
src/qemu/qemu_tpm.c | 31 ++++++++++++++-----------------
1 file changed, 14 insertions(+), 17 deletions(-)
diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c
index 584c787b700b..50e8c19f3a0b 100644
--- a/src/qemu/qemu_tpm.c
+++ b/src/qemu/qemu_tpm.c
@@ -795,28 +795,25 @@ 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) &&
+ (cmd = virCommandNew(swtpm_ioctl))) {
virCommandNew() succeeds, always.
- if (!swtpm_ioctl)
- return;
-
- if (!(pathname = qemuTPMEmulatorSocketBuildPath(swtpmStateDir, shortName)))
- return;
-
- if (!virFileExists(pathname))
- return;
-
- cmd = virCommandNew(swtpm_ioctl);
- if (!cmd)
- return;
+ virCommandAddArgList(cmd, "--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)
+ virPidFileDeletePath(pidfile);
Here, we can be more aggressive: virPidFileForceCleanupPath().
Reviewed-by: Michal Privoznik <mprivozn(a)redhat.com>
Michal