supervision - discussion about system services, daemon supervision, init, runlevel management, and tools such as s6 and runit
 help / color / mirror / Atom feed
From: Gerrit Pape <pape@smarden.org>
Subject: svlogd: blocking on ENOSPC
Date: Mon, 18 Oct 2004 17:39:24 +0000	[thread overview]
Message-ID: <20041018173902.24555.qmail@9227b11f156c29.315fe32.mid.smarden.org> (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')

             reply	other threads:[~2004-10-18 17:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-18 17:39 Gerrit Pape [this message]
2004-11-01 22:00 ` Csillag Tamás
2004-11-02 15:04   ` Gerrit Pape
2004-11-02 21:15     ` Csillag Tamas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20041018173902.24555.qmail@9227b11f156c29.315fe32.mid.smarden.org \
    --to=pape@smarden.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).