]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
logrotate qemu monitor logs
authorGuido Günther <agx@sigxcpu.org>
Tue, 9 Dec 2008 20:22:39 +0000 (20:22 +0000)
committerGuido Günther <agx@sigxcpu.org>
Tue, 9 Dec 2008 20:22:39 +0000 (20:22 +0000)
ChangeLog
qemud/Makefile.am
qemud/libvirtd.logrotate.in [new file with mode: 0644]
src/qemu_driver.c

index 0d7e806fd855cf0d4edde0fc877a0b6ea27cc717..a9332a3a55b84276fdbabcfefa5d6fd6c98d2653 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Tue 9 Dez 2008 21:08:43 CET Guido Günther <agx@sigxcpu.org>
+
+       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 <meyering@redhat.com>
 
        virsh.c: tweak options to produce more accurate help
index 31a41141f3bbaffd50e022b743e1a200f8ca1e33..df1e100a8cf74aa30e1db42d6bcae01f5785c3db 100644 (file)
@@ -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 (file)
index 0000000..9b42630
--- /dev/null
@@ -0,0 +1,8 @@
+@localstatedir@/log/libvirt/qemu/*.log {
+        daily
+        missingok
+        rotate 7
+        compress
+        delaycompress
+        copytruncate
+}
index 31c4886622b92aa10a6636a77a969c6a0821c9b2..5f6fbd19a90e06b2c98f129e9bfb1641fd53671d 100644 (file)
@@ -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));