[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH] Ensure logfile isn't truncated by shutdown message.



When running non-root, the QEMU log file is usually opened with
truncation, since there is no logrotate for non-root usage.
This means that when libvirt logs the shutdown timestamp, the
log is accidentally truncated

* src/qemu/qemu_driver.c: Never truncate log file with shutdown
  message
---
 src/qemu/qemu_driver.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index bf6cd0e..2a686dc 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -741,7 +741,7 @@ static int qemuCgroupControllerActive(struct qemud_driver *driver,
 }
 
 static int
-qemudLogFD(struct qemud_driver *driver, const char* name)
+qemudLogFD(struct qemud_driver *driver, const char* name, bool append)
 {
     char logfile[PATH_MAX];
     mode_t logmode;
@@ -756,7 +756,7 @@ qemudLogFD(struct qemud_driver *driver, const char* name)
 
     logmode = O_CREAT | O_WRONLY;
     /* Only logrotate files in /var/log, so only append if running privileged */
-    if (driver->privileged)
+    if (driver->privileged || append)
         logmode |= O_APPEND;
     else
         logmode |= O_TRUNC;
@@ -3964,7 +3964,7 @@ static int qemudStartVMDaemon(virConnectPtr conn,
     }
 
     DEBUG0("Creating domain log file");
-    if ((logfile = qemudLogFD(driver, vm->def->name)) < 0)
+    if ((logfile = qemudLogFD(driver, vm->def->name, false)) < 0)
         goto cleanup;
 
     DEBUG0("Determing emulator version");
@@ -4245,7 +4245,7 @@ static void qemudShutdownVMDaemon(struct qemud_driver *driver,
     VIR_DEBUG("Shutting down VM '%s' pid=%d migrated=%d",
               vm->def->name, vm->pid, migrated);
 
-    if ((logfile = qemudLogFD(driver, vm->def->name)) < 0) {
+    if ((logfile = qemudLogFD(driver, vm->def->name, true)) < 0) {
         /* To not break the normal domain shutdown process, skip the
          * timestamp log writing if failed on opening log file. */
         VIR_WARN("Unable to open logfile: %s",
-- 
1.7.2.3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]