]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Always send LOG_DEBUG to syslog(3) even if we are in quiet mode.
authorRoy Marples <roy@marples.name>
Thu, 19 Nov 2015 09:59:29 +0000 (09:59 +0000)
committerRoy Marples <roy@marples.name>
Thu, 19 Nov 2015 09:59:29 +0000 (09:59 +0000)
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.

common.c

index f8553da16cd11f7e64e301efe733321292d05d99..dd41e860562acb4222740b13003026865c1abb58 100644 (file)
--- 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