[libvirt] [PATCH 2/2] tpm: Create empty log file if file was removed

Stefan Berger posted 2 patches 6 years, 6 months ago
There is a newer version of this series
[libvirt] [PATCH 2/2] tpm: Create empty log file if file was removed
Posted by Stefan Berger 6 years, 6 months ago
Create an empty log file if the log file was removed, otherwise the
transaction to set the security labels on the file will fail.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
---
 src/qemu/qemu_tpm.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c
index 7efd635831..77ef601f74 100644
--- a/src/qemu/qemu_tpm.c
+++ b/src/qemu/qemu_tpm.c
@@ -340,9 +340,13 @@ qemuTPMEmulatorPrepareHost(virDomainTPMDefPtr tpm,
                     logDir, vmname) < 0)
         goto cleanup;
 
+    if (!virFileExists(tpm->data.emulator.logfile) &&
+        virFileTouch(tpm->data.emulator.logfile, 0644) < 0) {
+        goto cleanup;
+    }
+
     /* ... and make sure it can be accessed by swtpm_user */
-    if (virFileExists(tpm->data.emulator.logfile) &&
-        chown(tpm->data.emulator.logfile, swtpm_user, swtpm_group) < 0) {
+    if (chown(tpm->data.emulator.logfile, swtpm_user, swtpm_group) < 0) {
         virReportSystemError(errno,
                              _("Could not chown on swtpm logfile %s"),
                              tpm->data.emulator.logfile);
-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 2/2] tpm: Create empty log file if file was removed
Posted by Daniel P. Berrangé 6 years, 6 months ago
On Fri, Jul 26, 2019 at 11:51:47AM -0400, Stefan Berger wrote:
> Create an empty log file if the log file was removed, otherwise the
> transaction to set the security labels on the file will fail.
> 
> Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
> ---
>  src/qemu/qemu_tpm.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c
> index 7efd635831..77ef601f74 100644
> --- a/src/qemu/qemu_tpm.c
> +++ b/src/qemu/qemu_tpm.c
> @@ -340,9 +340,13 @@ qemuTPMEmulatorPrepareHost(virDomainTPMDefPtr tpm,
>                      logDir, vmname) < 0)
>          goto cleanup;
>  
> +    if (!virFileExists(tpm->data.emulator.logfile) &&
> +        virFileTouch(tpm->data.emulator.logfile, 0644) < 0) {
> +        goto cleanup;
> +    }
> +
>      /* ... and make sure it can be accessed by swtpm_user */
> -    if (virFileExists(tpm->data.emulator.logfile) &&
> -        chown(tpm->data.emulator.logfile, swtpm_user, swtpm_group) < 0) {
> +    if (chown(tpm->data.emulator.logfile, swtpm_user, swtpm_group) < 0) {
>          virReportSystemError(errno,
>                               _("Could not chown on swtpm logfile %s"),
>                               tpm->data.emulator.logfile);

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list