From 54f4ed6ba148d2576f25df5c083ce2b576a16968 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Tue, 9 Dec 2008 20:22:39 +0000 Subject: [PATCH] logrotate qemu monitor logs --- ChangeLog | 8 ++++++++ qemud/Makefile.am | 14 +++++++++++++- qemud/libvirtd.logrotate.in | 8 ++++++++ src/qemu_driver.c | 10 ++++++++-- 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 qemud/libvirtd.logrotate.in diff --git a/ChangeLog b/ChangeLog index 0d7e806fd8..a9332a3a55 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Tue 9 Dez 2008 21:08:43 CET Guido Günther + + logrotate qemu monitor logs + * src/qemu_driver.c: open logfile O_APPEND instead of O_TRUNC when + running as root + * qemud/Makefile.am: install logrotate configuration (by Harald Sraub) + and create logdir + Mon Dec 8 13:22:06 +0100 2008 Jim Meyering virsh.c: tweak options to produce more accurate help diff --git a/qemud/Makefile.am b/qemud/Makefile.am index 31a41141f3..df1e100a8c 100644 --- a/qemud/Makefile.am +++ b/qemud/Makefile.am @@ -134,7 +134,8 @@ endif default_xml_dest = libvirt/qemu/networks/default.xml -install-data-local: install-init install-data-sasl install-data-polkit +install-data-local: install-init install-data-sasl install-data-polkit \ + install-logrotate mkdir -p $(DESTDIR)$(sysconfdir)/libvirt/qemu/networks/autostart $(INSTALL_DATA) $(srcdir)/default-network.xml \ $(DESTDIR)$(sysconfdir)/$(default_xml_dest) @@ -198,6 +199,17 @@ remote_dispatch_ret.h: $(srcdir)/remote_generate_stubs.pl remote_protocol.x perl -w $(srcdir)/remote_generate_stubs.pl -r $(srcdir)/remote_protocol.x > $@ +libvirtd.logrotate: libvirtd.logrotate.in + sed \ + -e s!\@localstatedir\@!@localstatedir@!g \ + < $< > $@-t + mv $@-t $@ + +install-logrotate: libvirtd.logrotate + mkdir -p $(DESTDIR)$(localstatedir)/log/libvirt/qemu/ + mkdir -p $(DESTDIR)$(sysconfdir)/logrotate.d/ + $(INSTALL_DATA) $< $(DESTDIR)$(sysconfdir)/logrotate.d/libvirtd + if LIBVIRT_INIT_SCRIPTS_RED_HAT install-init: libvirtd.init mkdir -p $(DESTDIR)$(sysconfdir)/rc.d/init.d diff --git a/qemud/libvirtd.logrotate.in b/qemud/libvirtd.logrotate.in new file mode 100644 index 0000000000..9b42630135 --- /dev/null +++ b/qemud/libvirtd.logrotate.in @@ -0,0 +1,8 @@ +@localstatedir@/log/libvirt/qemu/*.log { + daily + missingok + rotate 7 + compress + delaycompress + copytruncate +} diff --git a/src/qemu_driver.c b/src/qemu_driver.c index 31c4886622..5f6fbd19a9 100644 --- a/src/qemu_driver.c +++ b/src/qemu_driver.c @@ -841,6 +841,8 @@ static int qemudStartVMDaemon(virConnectPtr conn, unsigned int qemuCmdFlags; fd_set keepfd; const char *emulator; + uid_t uid = geteuid(); + mode_t logmode; FD_ZERO(&keepfd); @@ -884,8 +886,12 @@ static int qemudStartVMDaemon(virConnectPtr conn, return -1; } - if ((vm->logfile = open(logfile, O_CREAT | O_TRUNC | O_WRONLY, - S_IRUSR | S_IWUSR)) < 0) { + logmode = O_CREAT | O_WRONLY; + if (uid != 0) + logmode |= O_TRUNC; + else + logmode |= O_APPEND; + if ((vm->logfile = open(logfile, logmode, S_IRUSR | S_IWUSR)) < 0) { qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, _("failed to create logfile %s: %s"), logfile, strerror(errno));