mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
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
This commit is contained in:
parent
dbf405bf04
commit
7f9cebc0c0
@ -741,7 +741,7 @@ static int qemuCgroupControllerActive(struct qemud_driver *driver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemudLogFD(struct qemud_driver *driver, const char* name)
|
qemudLogFD(struct qemud_driver *driver, const char* name, bool append)
|
||||||
{
|
{
|
||||||
char logfile[PATH_MAX];
|
char logfile[PATH_MAX];
|
||||||
mode_t logmode;
|
mode_t logmode;
|
||||||
@ -756,7 +756,7 @@ qemudLogFD(struct qemud_driver *driver, const char* name)
|
|||||||
|
|
||||||
logmode = O_CREAT | O_WRONLY;
|
logmode = O_CREAT | O_WRONLY;
|
||||||
/* Only logrotate files in /var/log, so only append if running privileged */
|
/* Only logrotate files in /var/log, so only append if running privileged */
|
||||||
if (driver->privileged)
|
if (driver->privileged || append)
|
||||||
logmode |= O_APPEND;
|
logmode |= O_APPEND;
|
||||||
else
|
else
|
||||||
logmode |= O_TRUNC;
|
logmode |= O_TRUNC;
|
||||||
@ -3976,7 +3976,7 @@ static int qemudStartVMDaemon(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
DEBUG0("Creating domain log file");
|
DEBUG0("Creating domain log file");
|
||||||
if ((logfile = qemudLogFD(driver, vm->def->name)) < 0)
|
if ((logfile = qemudLogFD(driver, vm->def->name, false)) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
emulator = vm->def->emulator;
|
emulator = vm->def->emulator;
|
||||||
@ -4271,7 +4271,7 @@ static void qemudShutdownVMDaemon(struct qemud_driver *driver,
|
|||||||
VIR_DEBUG("Shutting down VM '%s' pid=%d migrated=%d",
|
VIR_DEBUG("Shutting down VM '%s' pid=%d migrated=%d",
|
||||||
vm->def->name, vm->pid, migrated);
|
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
|
/* To not break the normal domain shutdown process, skip the
|
||||||
* timestamp log writing if failed on opening log file. */
|
* timestamp log writing if failed on opening log file. */
|
||||||
VIR_WARN("Unable to open logfile: %s",
|
VIR_WARN("Unable to open logfile: %s",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user