From: Ian Jackson Date: Sat, 8 May 2010 15:27:53 +0000 (+0100) Subject: use libinn logging where applicable - debugged X-Git-Tag: innduct-0.1~28 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=innduct.git;a=commitdiff_plain;h=bce50b7b81faf1c058436207300ac5b5c2c46df0;ds=sidebyside use libinn logging where applicable - debugged --- diff --git a/backends/innduct.c b/backends/innduct.c index 344b632..fc46fd3 100644 --- a/backends/innduct.c +++ b/backends/innduct.c @@ -540,15 +540,17 @@ static int until_connect, until_backlog_nextscan; static double accept_proportion; static int nocheck, nocheck_reported, in_child; -/* for simulation, debugging, etc. */ +/* for logging, simulation, debugging, etc. */ int simulate_flush= -1; +int logv_use_syslog; +static char *logv_prefix=""; /*========== logging ==========*/ static void logcore(int sysloglevel, const char *fmt, ...) PRINTF(2,3); static void logcore(int sysloglevel, const char *fmt, ...) { VA; - if (interactive < 2) { + if (logv_use_syslog) { vsyslog(sysloglevel,fmt,al); } else { if (self_pid) fprintf(stderr,"[%lu] ",(unsigned long)self_pid); @@ -569,13 +571,13 @@ static void logv(int sysloglevel, const char *pfx, int errnoval, if (sysloglevel >= LOG_ERR && (errnoval==EACCES || errnoval==EPERM)) sysloglevel= LOG_ERR; /* run by wrong user, probably */ - logcore(sysloglevel, "<%s>%s: %s%s%s", - sitename, pfx, msgbuf, - errnoval>=0 ? ": " : "", - errnoval>=0 ? strerror(errnoval) : ""); + logcore(sysloglevel, "%s%s: %s%s%s", + logv_prefix, pfx, msgbuf, + errnoval>=0 ? ": " : "", + errnoval>=0 ? strerror(errnoval) : ""); } -#define DIEWRAP(fn, pfx, sysloglevel, err, estatus) \ +#define DEFFATAL(fn, pfx, sysloglevel, err, estatus) \ static void fn(const char *fmt, ...) NORET_PRINTF(1,2); \ static void fn(const char *fmt, ...) { \ preterminate(); \ @@ -584,7 +586,7 @@ static void logv(int sysloglevel, const char *pfx, int errnoval, exit(estatus); \ } -#define LOGWRAP(fn, pfx, sysloglevel, err) \ +#define DEFLOG(fn, pfx, sysloglevel, err) \ static void fn(const char *fmt, ...) PRINTF(1,2); \ static void fn(const char *fmt, ...) { \ VA; \ @@ -592,11 +594,11 @@ static void logv(int sysloglevel, const char *pfx, int errnoval, va_end(al); \ } -#define INNLOGWRAP_DECLARE(fn, pfx, sysloglevel) \ - static void duct_log_##fn(int errval, const char *fmt, va_list al, int l) { \ +#define INNLOGSET_DECLARE(fn, pfx, sysloglevel) \ + static void duct_log_##fn(int l, const char *fmt, va_list al, int errval) { \ logv(sysloglevel, pfx, errval ? errval : -1, fmt, al); \ } -#define INNLOGWRAP_CALL(fn, pfx, sysloglevel) \ +#define INNLOGSET_CALL(fn, pfx, sysloglevel) \ message_handlers_##fn(1, duct_log_##fn); @@ -605,17 +607,18 @@ 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); +DEFFATAL(syscrash, "critical", LOG_CRIT, errno, 16); +DEFFATAL(crash, "critical", LOG_CRIT, -1, 16); -#define INNLOGWRAPS(INNLOGWRAP) \ - INNLOGWRAP(die, " fatal", LOG_ERR) \ - INNLOGWRAP(warn, " warning", LOG_WARNING) \ - INNLOGWRAP(notice, " notice", LOG_NOTICE) -INNLOGWRAPS(INNLOGWRAP_DECLARE) +#define INNLOGSETS(INNLOGSET) \ + INNLOGSET(die, "fatal", LOG_ERR) \ + INNLOGSET(warn, "warning", LOG_WARNING) \ + INNLOGSET(notice, "notice", LOG_NOTICE) \ + INNLOGSET(trace, "trace", LOG_NOTICE) +INNLOGSETS(INNLOGSET_DECLARE) -LOGWRAP(info, " info", LOG_INFO, -1) -LOGWRAP(dbg, " debug", LOG_DEBUG, -1) +DEFLOG(info, "info", LOG_INFO, -1) +DEFLOG(dbg, "debug", LOG_DEBUG, -1) /*========== utility functions etc. ==========*/ @@ -3721,7 +3724,7 @@ int main(int argc, char **argv) { /* set up libinn logging */ message_program_name= "innduct"; message_fatal_cleanup= innduct_fatal_cleanup; - INNLOGWRAPS(INNLOGWRAP_CALL) + INNLOGSETS(INNLOGSET_CALL) if (!argv[1]) { printusage(stderr); @@ -3826,8 +3829,11 @@ int main(int argc, char **argv) { close(i); } - if (interactive < 2) + logv_prefix= xasprintf("<%s> ", sitename); + if (interactive < 2) { openlog("innduct",LOG_NDELAY|LOG_PID,LOG_NEWS); + logv_use_syslog= 1; + } if (interactive < 1) { int null= open("/dev/null",O_RDWR);