},
};
-static int virTPMEmulatorInit(void);
+static int virTPMEmulatorInit(bool quiet);
static char *
virTPMBinaryGetPath(virTPMBinary binary)
virMutexLock(&swtpm_tools_lock);
- if (virTPMEmulatorInit() < 0)
+ if (virTPMEmulatorInit(false) < 0)
goto cleanup;
s = g_strdup(swtpmBinaries[binary].path);
return virTPMBinaryGetPath(VIR_TPM_BINARY_SWTPM_IOCTL);
}
+bool virTPMHasSwtpm(void)
+{
+ bool ret = false;
+
+ virMutexLock(&swtpm_tools_lock);
+
+ if (virTPMEmulatorInit(true) < 0)
+ goto cleanup;
+
+ ret = swtpmBinaries[VIR_TPM_BINARY_SWTPM].path != NULL &&
+ swtpmBinaries[VIR_TPM_BINARY_SWTPM_SETUP].path != NULL &&
+ swtpmBinaries[VIR_TPM_BINARY_SWTPM_IOCTL].path != NULL;
+
+ cleanup:
+ virMutexUnlock(&swtpm_tools_lock);
+ return ret;
+}
+
/* virTPMExecGetCaps
*
* Execute the prepared command and parse the returned JSON object
* executables that we will use to start and setup the swtpm
*/
static int
-virTPMEmulatorInit(void)
+virTPMEmulatorInit(bool quiet)
{
size_t i;
path = virFindFileInPath(virTPMBinaryTypeToString(i));
if (!path) {
- virReportSystemError(ENOENT,
- _("Unable to find '%s' binary in $PATH"),
- virTPMBinaryTypeToString(i));
+ if (!quiet)
+ virReportSystemError(ENOENT,
+ _("Unable to find '%s' binary in $PATH"),
+ virTPMBinaryTypeToString(i));
return -1;
}
if (!virFileIsExecutable(path)) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("%s is not an executable"),
- path);
+ if (!quiet)
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("%s is not an executable"),
+ path);
return -1;
}
if (stat(path, &swtpmBinaries[i].stat) < 0) {
- virReportSystemError(errno,
- _("Could not stat %s"), path);
+ if (!quiet)
+ virReportSystemError(errno,
+ _("Could not stat %s"), path);
return -1;
}
swtpmBinaries[i].path = g_steal_pointer(&path);
virMutexLock(&swtpm_tools_lock);
- if (virTPMEmulatorInit() < 0)
+ if (virTPMEmulatorInit(false) < 0)
goto cleanup;
if (!swtpmBinaries[binary].caps &&