From 01cf7a1bb9f1da27ad8bcbaa82c4f7a948c6a793 Mon Sep 17 00:00:00 2001 From: Stefan Berger Date: Thu, 25 Jul 2019 14:22:04 -0400 Subject: [PATCH] tpm: Check whether previously found executables were updated MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Check whether previously found executables were updated and if so look for them again. This helps to use updated features of swtpm and its tools upon updating them. Signed-off-by: Stefan Berger Reviewed-by: Marc-André Lureau Reviewed-by: Daniel P. Berrangé --- src/qemu/qemu_tpm.c | 1 + src/util/virtpm.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c index 7282b01bfe..9f1e7e20ba 100644 --- a/src/qemu/qemu_tpm.c +++ b/src/qemu/qemu_tpm.c @@ -20,6 +20,7 @@ #include +#include #include #include #include diff --git a/src/util/virtpm.c b/src/util/virtpm.c index 6df225f4e4..6228f3187d 100644 --- a/src/util/virtpm.c +++ b/src/util/virtpm.c @@ -78,8 +78,13 @@ virTPMCreateCancelPath(const char *devpath) */ static virMutex swtpm_tools_lock = VIR_MUTEX_INITIALIZER; static char *swtpm_path; +static struct stat swtpm_stat; + static char *swtpm_setup; +static struct stat swtpm_setup_stat; + static char *swtpm_ioctl; +static struct stat swtpm_ioctl_stat; char * virTPMGetSwtpm(void) @@ -139,18 +144,22 @@ virTPMEmulatorInit(void) static const struct { const char *name; char **path; + struct stat *stat; } prgs[] = { { .name = "swtpm", .path = &swtpm_path, + .stat = &swtpm_stat, }, { .name = "swtpm_setup", .path = &swtpm_setup, + .stat = &swtpm_setup_stat, }, { .name = "swtpm_ioctl", .path = &swtpm_ioctl, + .stat = &swtpm_ioctl_stat, } }; size_t i; @@ -160,8 +169,24 @@ virTPMEmulatorInit(void) for (i = 0; i < ARRAY_CARDINALITY(prgs); i++) { VIR_AUTOFREE(char *) path = NULL; bool findit = *prgs[i].path == NULL; + struct stat statbuf; + char *tmp; + + if (!findit) { + /* has executables changed? */ + if (stat(*prgs[i].path, &statbuf) < 0) + findit = true; + + if (!findit && + &statbuf.st_mtime != &prgs[i].stat->st_mtime) + findit = true; + } if (findit) { + tmp = *prgs[i].path; + VIR_FREE(tmp); + *prgs[i].path = NULL; + path = virFindFileInPath(prgs[i].name); if (!path) { virReportSystemError(ENOENT, @@ -175,7 +200,13 @@ virTPMEmulatorInit(void) path); goto cleanup; } + if (stat(path, prgs[i].stat) < 0) { + virReportSystemError(errno, + _("Could not stat %s"), path); + goto cleanup; + } *prgs[i].path = path; + path = NULL; } } -- GitLab