From 86bd7d002d353917712a4804d27cea8649e6e815 Mon Sep 17 00:00:00 2001 From: hadaq Date: Mon, 7 Oct 2002 11:51:09 +0000 Subject: [PATCH] Performance Boost (untested) -- mm --- compat/syslog.c | 59 +++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/compat/syslog.c b/compat/syslog.c index fd6bb0f..53e34ba 100644 --- a/compat/syslog.c +++ b/compat/syslog.c @@ -13,38 +13,39 @@ static unsigned ourLogopt = 0; static unsigned ourFacility = LOG_USER; void SYSLOG_syslog(int priority, const char *message, ...) { - va_list ap; - static const char *pri = "PACEWNID"; - char idPri[OUR_IDENT_LEN + 3]; - static const char *mode[] = { - "\033[0;1m\033[43;31m", - "\033[0;1m\033[43;39m", - "\033[43;39m", - "\033[0;1m\033[49;31m", - "\033[0;1m", - "\033[0;1m\033[49;32m", - "", - "", - "\033[49;39m\033[0m" - }; - - sprintf(idPri, "%s<%c>", ourIdent, pri[priority]); - - if ((ourLogopt & LOG_PERROR) && (ourMaskpri & (1 << priority))) { - fprintf(stderr, "%s", mode[priority]); - fprintf(stderr, "%s: ", idPri); + if (ourMaskpri & (1 << priority)) { + va_list ap; + static const char *pri = "PACEWNID"; + char idPri[OUR_IDENT_LEN + 3]; + + sprintf(idPri, "%s<%c>", ourIdent, pri[priority]); + if (ourLogopt & LOG_PERROR) { + static const char *mode[] = { + "\033[0;1m\033[43;31m", + "\033[0;1m\033[43;39m", + "\033[43;39m", + "\033[0;1m\033[49;31m", + "\033[0;1m", + "\033[0;1m\033[49;32m", + "", + "", + "\033[49;39m\033[0m" + }; + fprintf(stderr, "%s", mode[priority]); + fprintf(stderr, "%s: ", idPri); + va_start(ap, message); + vfprintf(stderr, message, ap); + va_end(ap); + fprintf(stderr, "%s", mode[LOG_DEBUG + 1]); + fprintf(stderr, "%c", '\n'); + } + + openlog(idPri, ourLogopt & ~LOG_PERROR, ourFacility); va_start(ap, message); - vfprintf(stderr, message, ap); + vsyslog(priority, message, ap); va_end(ap); - fprintf(stderr, "%s", mode[LOG_DEBUG + 1]); - fprintf(stderr, "%c", '\n'); + closelog(); } - - openlog(idPri, ourLogopt & ~LOG_PERROR, ourFacility); - va_start(ap, message); - vsyslog(priority, message, ap); - va_end(ap); - closelog(); } void SYSLOG_openlog(const char *ident, int logopt, int facility) { -- 2.43.0