]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tpm: Create empty log file if file was removed
authorStefan Berger <stefanb@linux.ibm.com>
Fri, 26 Jul 2019 21:07:06 +0000 (17:07 -0400)
committerEric Blake <eblake@redhat.com>
Fri, 26 Jul 2019 21:32:25 +0000 (16:32 -0500)
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>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Message-Id: <20190726210706.24440-3-stefanb@linux.ibm.com>

src/qemu/qemu_tpm.c

index 7efd6358310f0422cdfd5de821e57fd00a38c02e..77ef601f7405c869128346da86bed6b008d1ef5f 100644 (file)
@@ -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);