X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=secnet.git;a=blobdiff_plain;f=log.c;h=4f1b651d13735af9d899ff9988979fd87209fdb5;hp=6f4b7380198e7ad37dbf367d36b43b39a704e979;hb=ba72e2bf5e1a1cedc74f7de35e29cce7a0f4fca1;hpb=90a39563035b70196da9c5bdc7c17a63b64449b0 diff --git a/log.c b/log.c index 6f4b738..4f1b651 100644 --- a/log.c +++ b/log.c @@ -14,15 +14,26 @@ bool_t secnet_is_daemon=False; uint32_t message_level=M_WARNING|M_ERR|M_SECURITY|M_FATAL; struct log_if *system_log=NULL; -static void vMessage(uint32_t class, const char *message, va_list args) +static void vMessageFallback(uint32_t class, const char *message, va_list args) { FILE *dest=stdout; + /* Messages go to stdout/stderr */ + if (class & message_level) { + if (class&M_FATAL || class&M_ERR || class&M_WARNING) { + dest=stderr; + } + vfprintf(dest,message,args); + } +} + +static void vMessage(uint32_t class, const char *message, va_list args) +{ #define MESSAGE_BUFLEN 1023 static char buff[MESSAGE_BUFLEN+1]={0,}; size_t bp; char *nlp; - if (secnet_is_daemon) { + if (system_log) { /* Messages go to the system log interface */ bp=strlen(buff); assert(bp < MESSAGE_BUFLEN); @@ -34,13 +45,7 @@ static void vMessage(uint32_t class, const char *message, va_list args) memmove(buff,nlp+1,strlen(nlp+1)+1); } } else { - /* Messages go to stdout/stderr */ - if (class & message_level) { - if (class&M_FATAL || class&M_ERR || class&M_WARNING) { - dest=stderr; - } - vfprintf(dest,message,args); - } + vMessageFallback(class,message,args); } } @@ -53,6 +58,15 @@ void Message(uint32_t class, const char *message, ...) va_end(ap); } +static void MessageFallback(uint32_t class, const char *message, ...) +{ + va_list ap; + + va_start(ap,message); + vMessageFallback(class,message,ap); + va_end(ap); +} + static NORETURN(vfatal(int status, bool_t perror, const char *message, va_list args)); @@ -262,8 +276,8 @@ static void logfile_vlog(void *sst, int class, const char *message, fflush(st->f); } } else { - vMessage(class,message,args); - Message(class,"\n"); + vMessageFallback(class,message,args); + MessageFallback(class,"\n"); } } @@ -391,8 +405,8 @@ static void syslog_vlog(void *sst, int class, const char *message, if (st->open) vsyslog(msgclass_to_syslogpriority(class),message,args); else { - vMessage(class,message,args); - Message(class,"\n"); + vMessageFallback(class,message,args); + MessageFallback(class,"\n"); } }