supervision - discussion about system services, daemon supervision, init, runlevel management, and tools such as s6 and runit
 help / color / mirror / Atom feed
* svlogd: blocking on ENOSPC
@ 2004-10-18 17:39 Gerrit Pape
  2004-11-01 22:00 ` Csillag Tamás
  0 siblings, 1 reply; 4+ messages in thread
From: Gerrit Pape @ 2004-10-18 17:39 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 629 bytes --]

Hi, svlogd, just as multilog, sleeps and retries in case it's unable to
write to the current logfile in a log directory and the system is ``out
of disk space''.  This usually makes the service block because svlogd
stops reading from the pipe.  Even though the space for logs can be
calculated properly, if a log partition fills up by accident, it can
bring the system in a troublesome state.

Here's a patch that makes svlogd remove the oldest of rotated log files
in the log directory in case the disk is full.  In the worst case only
the current logfile will be left.  I would be interested in your
opinions.

Regards, Gerrit.

[-- Attachment #2: diff --]
[-- Type: text/plain, Size: 1676 bytes --]

diff -u -r1.7 -r1.8
--- src/svlogd.c	7 Oct 2004 07:56:29 -0000	1.7
+++ src/svlogd.c	7 Oct 2004 14:40:56 -0000	1.8
@@ -287,8 +287,41 @@
     if (len > ((dir +n)->sizemax -(dir +n)->size))
       len =(dir +n)->sizemax -(dir +n)->size;
   }
-  while ((i =write((dir +n)->fdcur, s, len)) == -1)
+  while ((i =write((dir +n)->fdcur, s, len)) == -1) {
+    if (errno == ENOSPC) {
+      DIR *d;
+      direntry *f;
+      char oldest[FMT_PTIME];
+
+      while (fchdir((dir +n)->fddir) == -1)
+        pause2("unable to change directory, want remove old logfile",
+               (dir +n)->name);
+      oldest[0] ='A'; oldest[1] =oldest[27] =0;
+      while (! (d =opendir(".")))
+        pause2("unable to open directory, want remove old logfile",
+               (dir +n)->name);
+      errno =0;
+      while ((f =readdir(d)))
+        if ((f->d_name[0] == '@') && (str_len(f->d_name) == 27))
+          if (str_diff(f->d_name, oldest) < 0) byte_copy(oldest, 27, f->d_name);
+      if (errno) warn2("unable to read directory, want remove old logfile",
+                       (dir +n)->name);
+      closedir(d);
+      if (*oldest == '@') {
+        strerr_warn5(WARNING, "out of disk space, delete: ", (dir +n)->name,
+                     "/", oldest, 0);
+        if (unlink(oldest) == -1)
+          warn2("unable to unlink oldest logfile", (dir +n)->name);
+        else
+          i =1;
+      }
+      while (fchdir(fdwdir) == -1)
+        pause1("unable to change to initial working directory");
+      if (i) continue;
+    }
     pause2("unable to write to current", (dir +n)->name);
+  }
+
   (dir +n)->size +=i;
   if ((dir +n)->sizemax)
     if (s[i -1] == '\n')

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-11-02 21:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-18 17:39 svlogd: blocking on ENOSPC Gerrit Pape
2004-11-01 22:00 ` Csillag Tamás
2004-11-02 15:04   ` Gerrit Pape
2004-11-02 21:15     ` Csillag Tamas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).