mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-28 16:45:26 +00:00
Don't use O_TRUNC when opening QEMU logfiles
SELinux wants all log files opened with O_APPEND. When
running non-root though, libvirtd likes to use O_TRUNC
to avoid log files growing in size indefinitely. Instead
of using O_TRUNC though, we can use O_APPEND and then
call ftruncate() which keeps SELinux happier.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit 639d5c4966
)
This commit is contained in:
parent
f4e3a2afa5
commit
a8ad93965f
@ -1446,12 +1446,22 @@ qemuDomainOpenLogHelper(struct qemud_driver *driver,
|
|||||||
{
|
{
|
||||||
char *logfile;
|
char *logfile;
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
|
bool trunc = false;
|
||||||
|
|
||||||
if (virAsprintf(&logfile, "%s/%s.log", driver->logDir, vm->def->name) < 0) {
|
if (virAsprintf(&logfile, "%s/%s.log", driver->logDir, vm->def->name) < 0) {
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* To make SELinux happy we always need to open in append mode.
|
||||||
|
* So we fake O_TRUNC by calling ftruncate after open instead
|
||||||
|
*/
|
||||||
|
if (oflags & O_TRUNC) {
|
||||||
|
oflags &= ~O_TRUNC;
|
||||||
|
oflags |= O_APPEND;
|
||||||
|
trunc = true;
|
||||||
|
}
|
||||||
|
|
||||||
if ((fd = open(logfile, oflags, mode)) < 0) {
|
if ((fd = open(logfile, oflags, mode)) < 0) {
|
||||||
virReportSystemError(errno, _("failed to create logfile %s"),
|
virReportSystemError(errno, _("failed to create logfile %s"),
|
||||||
logfile);
|
logfile);
|
||||||
@ -1463,6 +1473,13 @@ qemuDomainOpenLogHelper(struct qemud_driver *driver,
|
|||||||
VIR_FORCE_CLOSE(fd);
|
VIR_FORCE_CLOSE(fd);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
if (trunc &&
|
||||||
|
ftruncate(fd, 0) < 0) {
|
||||||
|
virReportSystemError(errno, _("failed to truncate %s"),
|
||||||
|
logfile);
|
||||||
|
VIR_FORCE_CLOSE(fd);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(logfile);
|
VIR_FREE(logfile);
|
||||||
|
Loading…
Reference in New Issue
Block a user