[rbldnsd] [PATCH] make rbldnsd logging to a pipe possible again

Rik van Riel riel at surriel.com
Sun Oct 31 22:18:01 MSK 2004


Hi,

With the Linux 2.6 kernel, or FreeBSD, an open of a pipe
(created with mkfifo) fails when there is no listener.
With the patch below, rbldnsd just keeps retrying if it
is supposed to log to a file, but didn't manage to open
a file descriptor.

It also throttles the logging of the error message, only
logging on the first failure after a successful opening
of the file descriptor.

cheers,

Rik
-- 
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." - Brian W. Kernighan


--- rbldnsd-0.993.1/rbldnsd.c.orig	2004-10-31 14:09:51.000000000 -0500
+++ rbldnsd-0.993.1/rbldnsd.c	2004-10-31 14:14:32.000000000 -0500
@@ -807,14 +807,22 @@

 static void reopenlog(void) {
   if (logfile) {
+    static int opened_lasttime = 1;
     int fd;
-    if (flog) fclose(flog);
+    if (flog)
+      fclose(flog);
     fd = open(logfile, O_WRONLY|O_APPEND|O_CREAT|O_NONBLOCK|O_LARGEFILE, 0644);
     if (fd < 0 || (flog = fdopen(fd, "a")) == NULL) {
-      dslog(LOG_WARNING, 0, "error (re)opening logfile `%.50s': %s",
+      if (opened_lasttime) {
+        dslog(LOG_WARNING, 0, "error (re)opening logfile `%.50s': %s",
             logfile, strerror(errno));
-      if (fd >= 0) close(fd);
+        opened_lasttime = 0;
+      }
+      if (fd >= 0)
+        close(fd);
       flog = NULL;
+    } else {
+      opened_lasttime = 1;
     }
   }
   else if (flog && !flushlog) { /* log to stdout */
@@ -967,6 +975,8 @@
   r = replypacket(&pkt, q, zonelist);
   if (!r)
     return;
+  if (logfile && !flog)
+    reopenlog();
   if (flog)
     logreply(&pkt, (struct sockaddr *)&sa, salen, flog, flushlog);



More information about the rbldnsd mailing list