tpm: Refactor virTPMEmulatorInit to use loop
Refactor virTPMEmulatorInit to use a loop with parameters. This allows for easier extension later on. Signed-off-by: Stefan Berger <stefanb@linux.ibm.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
4777bbdd76
commit
2fcbe9f97d
@ -136,54 +136,46 @@ int
|
|||||||
virTPMEmulatorInit(void)
|
virTPMEmulatorInit(void)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
static const struct {
|
||||||
|
const char *name;
|
||||||
|
char **path;
|
||||||
|
} prgs[] = {
|
||||||
|
{
|
||||||
|
.name = "swtpm",
|
||||||
|
.path = &swtpm_path,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.name = "swtpm_setup",
|
||||||
|
.path = &swtpm_setup,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.name = "swtpm_ioctl",
|
||||||
|
.path = &swtpm_ioctl,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
size_t i;
|
||||||
|
|
||||||
virMutexLock(&swtpm_tools_lock);
|
virMutexLock(&swtpm_tools_lock);
|
||||||
|
|
||||||
if (!swtpm_path) {
|
for (i = 0; i < ARRAY_CARDINALITY(prgs); i++) {
|
||||||
swtpm_path = virFindFileInPath("swtpm");
|
VIR_AUTOFREE(char *) path = NULL;
|
||||||
if (!swtpm_path) {
|
bool findit = *prgs[i].path == NULL;
|
||||||
virReportSystemError(ENOENT, "%s",
|
|
||||||
_("Unable to find 'swtpm' binary in $PATH"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
if (!virFileIsExecutable(swtpm_path)) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("TPM emulator %s is not an executable"),
|
|
||||||
swtpm_path);
|
|
||||||
VIR_FREE(swtpm_path);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!swtpm_setup) {
|
if (findit) {
|
||||||
swtpm_setup = virFindFileInPath("swtpm_setup");
|
path = virFindFileInPath(prgs[i].name);
|
||||||
if (!swtpm_setup) {
|
if (!path) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportSystemError(ENOENT,
|
||||||
_("Could not find 'swtpm_setup' in PATH"));
|
_("Unable to find '%s' binary in $PATH"),
|
||||||
goto cleanup;
|
prgs[i].name);
|
||||||
}
|
goto cleanup;
|
||||||
if (!virFileIsExecutable(swtpm_setup)) {
|
}
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
if (!virFileIsExecutable(path)) {
|
||||||
_("'%s' is not an executable"),
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
swtpm_setup);
|
_("%s is not an executable"),
|
||||||
VIR_FREE(swtpm_setup);
|
path);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
*prgs[i].path = path;
|
||||||
|
|
||||||
if (!swtpm_ioctl) {
|
|
||||||
swtpm_ioctl = virFindFileInPath("swtpm_ioctl");
|
|
||||||
if (!swtpm_ioctl) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
||||||
_("Could not find swtpm_ioctl in PATH"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
if (!virFileIsExecutable(swtpm_ioctl)) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("swtpm_ioctl program %s is not an executable"),
|
|
||||||
swtpm_ioctl);
|
|
||||||
VIR_FREE(swtpm_ioctl);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user