Re: [PATCH] qemu: Do not keep swtmp pidfile around after stopping

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Aug 18, 2022 at 04:20:56PM +0200, 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.


Forgot to mention the BZ:

https://bugzilla.redhat.com/show_bug.cgi?id=2111301

Signed-off-by: Martin Kletzander <mkletzan@xxxxxxxxxx>
---
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))) {

-    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);
}


--
2.37.2

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux