]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
log: make a copy of va when logging to both stderr and syslog
authorVincent Bernat <vincent@bernat.im>
Mon, 16 May 2016 06:56:56 +0000 (08:56 +0200)
committerVincent Bernat <vincent@bernat.im>
Mon, 16 May 2016 06:56:56 +0000 (08:56 +0200)
On common platform, the copy is cheap. In case it isn't we note that the
copy doesn't happen if using a log handler and syslog cannot be enabled
with debug messages.

src/log.c

index 8c85d5a111d64921c1acdeaaf6a47911e2bb8a3d..6596950eb49abebe4de6811a410ae3e502666084 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -149,6 +149,12 @@ vlog(int pri, const char *token, const char *fmt, va_list ap)
                return;
        }
 
+       /* Log to syslog if requested */
+       if (use_syslog) {
+               va_list ap2;
+               va_copy(ap2, ap);
+               vsyslog(pri, fmt, ap2);
+               va_end(ap2);
        }
 
        /* Log to standard error in all cases */
@@ -167,10 +173,6 @@ vlog(int pri, const char *token, const char *fmt, va_list ap)
                free(nfmt);
        }
        fflush(stderr);
-
-       /* Log to syslog if requested */
-       if (use_syslog)
-               vsyslog(pri, fmt, ap);
 }