chiark / gitweb /
use libinn logging where applicable - compiles
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 8 May 2010 15:08:39 +0000 (16:08 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 8 May 2010 15:08:39 +0000 (16:08 +0100)
backends/innduct.c

index 44a07c753b25f57ea8a287d22aab478530ae0f2d..00bbe2d141308446dc4fadfa456ed4e8f8b05e1e 100644 (file)
@@ -182,6 +182,7 @@ perl -ne 'print if m/-8\<-/..m/-\>8-/; print "\f" if m/-\^L-/' backends/innduct.
 
 #include "inn/list.h"
 #include "inn/innconf.h"
+#include "inn/messages.h"
 
 #include <sys/uio.h>
 #include <sys/types.h>
@@ -333,7 +334,6 @@ static void close_defer(void);
 static void search_backlog_file(void);
 static void preterminate(void);
 static void raise_default(int signo) NORET;
-static char *debug_report_ipf(InputFile *ipf);
 
 static void inputfile_reading_start(InputFile *ipf);
 static void inputfile_reading_stop(InputFile *ipf);
@@ -575,7 +575,7 @@ static void logv(int sysloglevel, const char *pfx, int errnoval,
         errnoval>=0 ? strerror(errnoval) : "");
 }
 
-#define diewrap(fn, pfx, sysloglevel, err, estatus)            \
+#define DIEWRAP(fn, pfx, sysloglevel, err, estatus)            \
   static void fn(const char *fmt, ...) NORET_PRINTF(1,2);      \
   static void fn(const char *fmt, ...) {                       \
     preterminate();                                            \
@@ -584,7 +584,7 @@ static void logv(int sysloglevel, const char *pfx, int errnoval,
     exit(estatus);                                             \
   }
 
-#define logwrap(fn, pfx, sysloglevel, err)             \
+#define LOGWRAP(fn, pfx, sysloglevel, err)             \
   static void fn(const char *fmt, ...) PRINTF(1,2);    \
   static void fn(const char *fmt, ...) {               \
     VA;                                                        \
@@ -594,10 +594,10 @@ static void logv(int sysloglevel, const char *pfx, int errnoval,
 
 #define INNLOGWRAP_DECLARE(fn, pfx, sysloglevel)                             \
   static void duct_log_##fn(int errval, const char *fmt, va_list al, int l) { \
-    logv(sysloglevel, pfx, errnoval ? errnoval : -1, fmt, al);               \
+    logv(sysloglevel, pfx, errval ? errval : -1, fmt, al);                   \
   }
 #define INNLOGWRAP_CALL(fn, pfx, sysloglevel)  \
-  fn##_set_handlers(1, duct_log_##fn);
+  message_handlers_##fn(1, duct_log_##fn);
 
 
 static int innduct_fatal_cleanup(void) { return 12; } /* used for libinn die */
@@ -605,19 +605,19 @@ static int innduct_fatal_cleanup(void) { return 12; } /* used for libinn die */
 /* We want to extend the set of logging functions from inn, and we
  * want to prepend the site name to all our messages. */
 
-diewrap(syscrash,    " critical", LOG_CRIT,    errno, 16);
-diewrap(crash,       " critical", LOG_CRIT,    -1,    16);
+DIEWRAP(syscrash,    " critical", LOG_CRIT,    errno, 16);
+DIEWRAP(crash,       " critical", LOG_CRIT,    -1,    16);
 
-diewrap(sysfatal,    " fatal",    LOG_ERR,     errno, 12);
-diewrap(fatal,       " fatal",    LOG_ERR,     -1,    12);
+DIEWRAP(sysfatal,    " fatal",    LOG_ERR,     errno, 12);
+DIEWRAP(fatal,       " fatal",    LOG_ERR,     -1,    12);
 
-#define INNLOGWRAPS                                    \
-  INNLOGWRAP(warn,   " warning",  LOG_WARNING, errno)  \
-  INNLOGWRAP(notice, " notice",   LOG_NOTICE,  -1)
+#define INNLOGWRAPS(INNLOGWRAP)                        \
+  INNLOGWRAP(warn,   " warning",  LOG_WARNING) \
+  INNLOGWRAP(notice, " notice",   LOG_NOTICE)
 INNLOGWRAPS(INNLOGWRAP_DECLARE)
 
-logwrap(info,        " info",     LOG_INFO,    -1);
-logwrap(debug,       " debug",    LOG_DEBUG,   -1);
+LOGWRAP(info,        " info",     LOG_INFO,    -1)
+LOGWRAP(dbg,         " debug",    LOG_DEBUG,   -1)
 
 
 /*========== utility functions etc. ==========*/
@@ -663,7 +663,7 @@ static pid_t mfork(const char *what) {
 
   child= fork();
   if (child==-1) sysfatal("cannot fork for %s",what);
-  debug("forked %s %ld", what, (unsigned long)child);
+  dbg("forked %s %ld", what, (unsigned long)child);
   if (!child) postfork();
   return child;
 }
@@ -1197,7 +1197,7 @@ static void conn_idle_close(Conn *conn, const char *why) {
     if (!todo) {
       conn->quitting= why;
       conn->since_activity= 0;
-      debug("C%d is idle (%s), quitting", conn->fd, why);
+      dbg("C%d is idle (%s), quitting", conn->fd, why);
       break;
     }
   }
@@ -1908,7 +1908,7 @@ static void update_nocheck(int accepted) {
     notice("entering nocheck mode for the first time");
     nocheck_reported= 1;
   } else if (new_nocheck != nocheck) {
-    debug("nocheck mode %s", new_nocheck ? "start" : "stop");
+    dbg("nocheck mode %s", new_nocheck ? "start" : "stop");
   }
   nocheck= new_nocheck;
 }
@@ -2309,15 +2309,15 @@ static void filemon_method_startfile(InputFile *ipf, Filemon_Perfile *pf) {
   assert(!filemon_inotify_wd2ipf[wd]);
   filemon_inotify_wd2ipf[wd]= ipf;
 
-  debug("filemon inotify startfile %p wd=%d wdmax=%d",
-       ipf, wd, filemon_inotify_wdmax);
+  dbg("filemon inotify startfile %p wd=%d wdmax=%d",
+      ipf, wd, filemon_inotify_wdmax);
 
   pf->wd= wd;
 }
 
 static void filemon_method_stopfile(InputFile *ipf, Filemon_Perfile *pf) {
   int wd= pf->wd;
-  debug("filemon inotify stopfile %p wd=%d", ipf, wd);
+  dbg("filemon inotify stopfile %p wd=%d", ipf, wd);
   int r= inotify_rm_watch(filemon_inotify_fd, wd);
   if (r) syscrash("inotify_rm_watch");
   filemon_inotify_wd2ipf[wd]= 0;
@@ -2337,7 +2337,7 @@ static void *filemon_inotify_readable(oop_source *lp, int fd,
       crash("inotify read %d bytes wanted struct of %d", r, (int)sizeof(iev));
     }
     InputFile *ipf= filemon_inotify_wd2ipf[iev.wd];
-    /*debug("filemon inotify readable read %p wd=%d", ipf, iev.wd);*/
+    /*dbg("filemon inotify readable read %p wd=%d", ipf, iev.wd);*/
     tailing_make_readable(ipf);
   }
   return OOP_CONTINUE;
@@ -2352,7 +2352,7 @@ static int filemon_method_init(void) {
   msetnonblock(filemon_inotify_fd, 1);
   loop->on_fd(loop, filemon_inotify_fd, OOP_READ, filemon_inotify_readable, 0);
 
-  debug("filemon inotify init filemon_inotify_fd=%d", filemon_inotify_fd);
+  dbg("filemon inotify init filemon_inotify_fd=%d", filemon_inotify_fd);
   return 1;
 }
 
@@ -2602,7 +2602,7 @@ static void statemc_lock(void) {
       fflush(lockfile))
     sysfatal("write info to lockfile %s", path_lock);
 
-  debug("startup: locked");
+  dbg("startup: locked");
 }
 
 static void statemc_init(void) {
@@ -2613,9 +2613,9 @@ static void statemc_init(void) {
   int defer_noent;
   mlstat_isreg(path_defer, &stabdefer, &defer_noent, "defer file");
   if (defer_noent) {
-    debug("startup: ductdefer ENOENT");
+    dbg("startup: ductdefer ENOENT");
   } else {
-    debug("startup: ductdefer nlink=%ld", (long)stabdefer.st_nlink);
+    dbg("startup: ductdefer nlink=%ld", (long)stabdefer.st_nlink);
     switch (stabdefer.st_nlink==1) {
     case 1:
       open_defer(); /* so that we will later close it and rename it */
@@ -2639,19 +2639,19 @@ static void statemc_init(void) {
   mlstat_isreg(feedfile, &stab_f, &noent_f, "feedfile");
 
   if (!noent_f && file_d && samefile(&stab_f, &stab_d)) {
-    debug("startup: F==D => Hardlinked");
+    dbg("startup: F==D => Hardlinked");
     munlink(feedfile, "feed file (during startup)"); /* => Moved */
     noent_f= 1;
   }
 
   if (noent_f) {
-    debug("startup: F ENOENT => Moved");
+    dbg("startup: F ENOENT => Moved");
     if (file_d) startup_set_input_file(file_d);
     spawn_inndcomm_flush("feedfile missing at startup");
     /* => Flushing, sms:=FLUSHING */
   } else {
     if (file_d) {
-      debug("startup: F!=D => Separated");
+      dbg("startup: F!=D => Separated");
       startup_set_input_file(file_d);
       flushing_input_file= main_input_file;
       main_input_file= open_input_file(feedfile);
@@ -2659,7 +2659,7 @@ static void statemc_init(void) {
       SMS(SEPARATED, max_separated_periods,
          "found both old and current feed files");
     } else {
-      debug("startup: F exists, D ENOENT => Normal");
+      dbg("startup: F exists, D ENOENT => Normal");
       InputFile *file_f= open_input_file(feedfile);
       if (!file_f) crash("feed file vanished during startup");
       startup_set_input_file(file_f);
@@ -2671,7 +2671,7 @@ static void statemc_init(void) {
 static void statemc_start_flush(const char *why) { /* Normal => Flushing */
   assert(sms == sm_NORMAL);
 
-  debug("starting flush (%s) (%lu >?= %lu) (%d)",
+  dbg("starting flush (%s) (%lu >?= %lu) (%d)",
        why,
        (unsigned long)(main_input_file ? main_input_file->offset : 0),
        (unsigned long)target_max_feedfile_size,
@@ -2970,7 +2970,7 @@ static void search_backlog_file(void) {
       const char *path= gl.gl_pathv[i];
 
       if (strchr(path,'#') || strchr(path,'~')) {
-       debug("backlog file search skipping %s", path);
+       dbg("backlog file search skipping %s", path);
        continue;
       }
       r= stat(path, &stab);
@@ -2995,7 +2995,7 @@ static void search_backlog_file(void) {
   }
 
   if (!oldest_path) {
-    debug("backlog scan: none");
+    dbg("backlog scan: none");
 
     if (sms==sm_DROPPED) {
       preterminate();
@@ -3017,7 +3017,7 @@ static void search_backlog_file(void) {
   long age_deficiency= (backlog_retry_minperiods * period_seconds) - age;
 
   if (age_deficiency <= 0) {
-    debug("backlog scan: found age=%f deficiency=%ld oldest=%s",
+    dbg("backlog scan: found age=%f deficiency=%ld oldest=%s",
          age, age_deficiency, oldest_path);
 
     backlog_input_file= open_input_file(oldest_path);
@@ -3037,7 +3037,7 @@ static void search_backlog_file(void) {
       until_backlog_nextscan > backlog_spontrescan_periods)
     until_backlog_nextscan= backlog_spontrescan_periods;
 
-  debug("backlog scan: young age=%f deficiency=%ld nextscan=%d oldest=%s",
+  dbg("backlog scan: young age=%f deficiency=%ld nextscan=%d oldest=%s",
        age, age_deficiency, until_backlog_nextscan, oldest_path);
 
  xfree:
@@ -3313,7 +3313,7 @@ static void filepoll(void) {
   tailing_make_readable(flushing_input_file);
 }
 
-static char *debug_report_ipf(InputFile *ipf) {
+static char *dbg_report_ipf(InputFile *ipf) {
   if (!ipf) return masprintf("none");
 
   const char *slash= strrchr(ipf->path,'/');
@@ -3329,19 +3329,19 @@ static char *debug_report_ipf(InputFile *ipf) {
 }
 
 static void period(void) {
-  char *dipf_main=     debug_report_ipf(main_input_file);
-  char *dipf_flushing= debug_report_ipf(flushing_input_file);
-  char *dipf_backlog=  debug_report_ipf(backlog_input_file);
-
-  debug("PERIOD"
-       " sms=%s[%d] conns=%d until_connect=%d"
-       " input_files main:%s flushing:%s backlog:%s[%d]"
-       " children connecting=%ld inndcomm=%ld lowvol_total=%d"
-       ,
-       sms_names[sms], until_flush, conns.count, until_connect,
-       dipf_main, dipf_flushing, dipf_backlog, until_backlog_nextscan,
-       (long)connecting_child, (long)inndcomm_child, lowvol_total
-       );
+  char *dipf_main=     dbg_report_ipf(main_input_file);
+  char *dipf_flushing= dbg_report_ipf(flushing_input_file);
+  char *dipf_backlog=  dbg_report_ipf(backlog_input_file);
+
+  dbg("PERIOD"
+      " sms=%s[%d] conns=%d until_connect=%d"
+      " input_files main:%s flushing:%s backlog:%s[%d]"
+      " children connecting=%ld inndcomm=%ld lowvol_total=%d"
+      ,
+      sms_names[sms], until_flush, conns.count, until_connect,
+      dipf_main, dipf_flushing, dipf_backlog, until_backlog_nextscan,
+      (long)connecting_child, (long)inndcomm_child, lowvol_total
+      );
 
   free(dipf_main);
   free(dipf_flushing);
@@ -3379,7 +3379,7 @@ static void dump_article_list(FILE *f, const CliCommand *c,
   
 static void dump_input_file(FILE *f, const CliCommand *c,
                            InputFile *ipf, const char *wh) {
-  char *dipf= debug_report_ipf(ipf);
+  char *dipf= dbg_report_ipf(ipf);
   fprintf(f,"input %s %s", wh, dipf);
   free(dipf);
   
@@ -3506,7 +3506,7 @@ static void vbadusage(const char *fmt, va_list al) {
          "say --help for help, or read the manpage\n",
          m);
   if (interactive < 2)
-    syslog(LOG_CRASH,"innduct: invoked with bad usage: %s",m);
+    syslog(LOG_ERR,"innduct: invoked with bad usage: %s",m);
   exit(8);
 }
 
@@ -3732,7 +3732,7 @@ static int path_ends_slash(const char *specified) {
 
 int main(int argc, char **argv) {
   /* set up libinn logging */
-  error_program_name= "innduct";
+  message_program_name= "innduct";
   message_fatal_cleanup= innduct_fatal_cleanup;
   INNLOGWRAPS(INNLOGWRAP_CALL)