Hey,

I saw someone [1] having problems with svlogd, when the logging
application produces no output for a longer time.

The admin wants to conform to GDPR, so he might have a config like:

t86400
n30

However, since empty files are not rotated, there will be logs older
than 30 days, if there is no new output for longer than a day.

I made a quick patch. Comments are welcome.


Martin Castillo

[1]: https://gitlab.com/gitlab-org/omnibus-gitlab/issues/4663
-- 
GPG: 7FDE 7190 2F73 2C50 236E  403D CC13 48F1 E644 08EC

diff '--exclude=command' '--exclude=compile' -Nur runit-2.1.2/man/svlogd.8 runit-2.1.3/man/svlogd.8
--- runit-2.1.2/man/svlogd.8	2014-08-10 20:22:09.000000000 +0200
+++ runit-2.1.3/man/svlogd.8	2019-11-15 15:40:11.023988168 +0100
@@ -3,7 +3,7 @@
 svlogd \- runit's service logging daemon
 .SH SYNOPSIS
 .B svlogd
-[\-tttv] [\-r
+[\-tttve] [\-r
 .I c\fR] [\-R
 .I xyz\fR] [\-l
 .I len\fR] [\-b
@@ -234,6 +234,11 @@
 seconds old, and is not empty,
 .B svlogd
 forces log file rotation.
+If -e was given at the commandline,
+.B svlogd
+rotates
+.I current
+even if it is empty.
 .TP
 .RI ! processor
 tells
@@ -417,6 +422,16 @@
 instances that process a lot of data in short time, the buffer size should
 be increased to improve performance.
 .TP
+.B \-e
+rotate empty.
+Rotate files even if they are empty.
+This can be used to ensure all logs are younger than a certain age,
+even if no log data comes in for a longer period in time.
+Use with
+.I timeout
+in
+.I config\fR.
+.TP
 .B \-v
 verbose.
 Print verbose messages to standard error.
@@ -449,7 +464,9 @@
 .I logs
 with a non empty
 .I current
-log file.
+log file. When invoked with -e, all
+.I logs
+are rotated.
 .SH SEE ALSO
 sv(8),
 runsv(8),
diff '--exclude=command' '--exclude=compile' -Nur runit-2.1.2/src/svlogd.c runit-2.1.3/src/svlogd.c
--- runit-2.1.2/src/svlogd.c	2019-11-15 14:34:05.759452761 +0100
+++ runit-2.1.3/src/svlogd.c	2019-11-15 15:46:39.555806222 +0100
@@ -33,7 +33,7 @@
 #include "ndelay.h"
 #include "iopause.h"
 
-#define USAGE " [-ttv] [-r c] [-R abc] [-l len] [-b buflen] dir ..."
+#define USAGE " [-tttve] [-r c] [-R abc] [-l len] [-b buflen] dir ..."
 #define VERSION "$Id: 5e55a90e0a1b35ec47fed3021453c50675ea1117 $"
 
 #define FATAL "svlogd: fatal: "
@@ -69,6 +69,7 @@
 unsigned int reopenasap =0;
 unsigned int linecomplete =1;
 unsigned int tmaxflag =0;
+unsigned int rotateempty =0;
 int fdudp =-1;
 iopause_fd in;
 
@@ -278,7 +279,7 @@
     if (taia_less(&ld->trotate, &trotate)) trotate =ld->trotate;
   }
 
-  if (ld->size > 0) {
+  if (ld->size > 0 || rotateempty) {
     buffer_flush(&ld->b);
     while (fsync(ld->fdcur) == -1)
       pause2("unable to fsync current logfile", ld->name);
@@ -667,7 +668,7 @@
 
   progname =*argv;
 
-  while ((opt =getopt(argc, argv, "R:r:l:b:tvV")) != opteof) {
+  while ((opt =getopt(argc, argv, "R:r:l:b:tvVe")) != opteof) {
     switch(opt) {
     case 'R':
       replace =optarg;
@@ -691,6 +692,9 @@
     case 'v':
       ++verbose;
       break;
+    case 'e':
+      rotateempty = 1;
+      break;
     case 'V': strerr_warn1(VERSION, 0);
     case '?': usage();
     }

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to