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

index d9091d6f89804178b53b05e0d32659b22777403a..44a07c753b25f57ea8a287d22aab478530ae0f2d 100644 (file)
@@ -592,18 +592,32 @@ static void logv(int sysloglevel, const char *pfx, int errnoval,
     va_end(al);                                                \
   }
 
-diewrap(syscrash, " critical", LOG_CRIT,    errno, 16);
-diewrap(crash,    " critical", LOG_CRIT,    -1,    16);
+#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);               \
+  }
+#define INNLOGWRAP_CALL(fn, pfx, sysloglevel)  \
+  fn##_set_handlers(1, duct_log_##fn);
+
+
+static int innduct_fatal_cleanup(void) { return 12; } /* used for libinn die */
 
-diewrap(sysfatal, " fatal",    LOG_ERR,     errno, 12);
-diewrap(fatal,    " fatal",    LOG_ERR,     -1,    12);
+/* We want to extend the set of logging functions from inn, and we
+ * want to prepend the site name to all our messages. */
 
-logwrap(syswarn,  " warning",  LOG_WARNING, errno);
-logwrap(warn,     " warning",  LOG_WARNING, -1);
+diewrap(syscrash,    " critical", LOG_CRIT,    errno, 16);
+diewrap(crash,       " critical", LOG_CRIT,    -1,    16);
 
-logwrap(notice,   " notice",   LOG_NOTICE,  -1);
-logwrap(info,     " info",     LOG_INFO,    -1);
-logwrap(debug,    " debug",    LOG_DEBUG,   -1);
+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)
+INNLOGWRAPS(INNLOGWRAP_DECLARE)
+
+logwrap(info,        " info",     LOG_INFO,    -1);
+logwrap(debug,       " debug",    LOG_DEBUG,   -1);
 
 
 /*========== utility functions etc. ==========*/
@@ -3717,6 +3731,11 @@ static int path_ends_slash(const char *specified) {
 }
 
 int main(int argc, char **argv) {
+  /* set up libinn logging */
+  error_program_name= "innduct";
+  message_fatal_cleanup= innduct_fatal_cleanup;
+  INNLOGWRAPS(INNLOGWRAP_CALL)
+
   if (!argv[1]) {
     printusage(stderr);
     exit(8);
@@ -3737,7 +3756,7 @@ int main(int argc, char **argv) {
   /* defaults */
 
   int r= innconf_read(inndconffile);
-  if (!r) badusage("could not read inn.conf (more info on stderr)");
+  if (!r) badusage("could not read inn.conf");
 
   if (!remote_host) remote_host= sitename;