From: Roy Marples Date: Thu, 19 Nov 2015 09:59:29 +0000 (+0000) Subject: Always send LOG_DEBUG to syslog(3) even if we are in quiet mode. X-Git-Tag: v6.9.4~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d9434ddc94b80213d63cc8000bcd421be225abc2;p=thirdparty%2Fdhcpcd.git Always send LOG_DEBUG to syslog(3) even if we are in quiet mode. It's upto syslog to filter it. While here, ensure that errno is set in the HAVE_PRINTF_M case for each time we use it. --- diff --git a/common.c b/common.c index f8553da1..dd41e860 100644 --- a/common.c +++ b/common.c @@ -113,9 +113,6 @@ logger(struct dhcpcd_ctx *ctx, int pri, const char *fmt, ...) char fmt_cpy[1024]; #endif - if (pri >= LOG_DEBUG && ctx && !(ctx->options & DHCPCD_DEBUG)) - return; - serrno = errno; va_start(va, fmt); @@ -166,38 +163,49 @@ logger(struct dhcpcd_ctx *ctx, int pri, const char *fmt, ...) } #endif - if (ctx == NULL || !(ctx->options & DHCPCD_QUIET)) { + if ((ctx == NULL || !(ctx->options & DHCPCD_QUIET)) && + (pri < LOG_DEBUG || (ctx->options & DHCPCD_DEBUG))) + { va_list vac; va_copy(vac, va); +#ifdef HAVE_PRINTF_M + errno = serrno; +#endif vfprintf(pri <= LOG_ERR ? stderr : stdout, fmt, vac); fputc('\n', pri <= LOG_ERR ? stderr : stdout); va_end(vac); } + if (ctx && ctx->log_fd != -1) { + if (pri < LOG_DEBUG || (ctx->options & DHCPCD_DEBUG)) { + struct timeval tv; + char buf[32]; + + /* Write the time, syslog style. month day time - */ + if (gettimeofday(&tv, NULL) != -1) { + time_t now; + struct tm tmnow; + + tzset(); + now = tv.tv_sec; + localtime_r(&now, &tmnow); + strftime(buf, sizeof(buf), "%b %d %T ", &tmnow); + dprintf(ctx->log_fd, "%s", buf); + } + #ifdef HAVE_PRINTF_M - errno = serrno; + errno = serrno; #endif - if (ctx && ctx->log_fd != -1) { - struct timeval tv; - char buf[32]; - - /* Write the time, syslog style. month day time - */ - if (gettimeofday(&tv, NULL) != -1) { - time_t now; - struct tm tmnow; - - tzset(); - now = tv.tv_sec; - localtime_r(&now, &tmnow); - strftime(buf, sizeof(buf), "%b %d %T ", &tmnow); - dprintf(ctx->log_fd, "%s", buf); + vdprintf(ctx->log_fd, fmt, va); + dprintf(ctx->log_fd, "\n"); } - - vdprintf(ctx->log_fd, fmt, va); - dprintf(ctx->log_fd, "\n"); - } else + } else { +#ifdef HAVE_PRINTF_M + errno = serrno; +#endif vsyslog(pri, fmt, va); + } va_end(va); } #endif