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