about summary refs log tree commit diff
path: root/src/misc/syslog.c
diff options
context:
space:
mode:
authorClément Vasseur <clement.vasseur@gmail.com>2014-07-09 14:34:18 +0200
committerRich Felker <dalias@aerifal.cx>2014-07-11 20:03:21 -0400
commitda27118157c2942d7652138b8d8b0056fc8f872f (patch)
treee34d5ce65623b928b5506be514e04d2a08f057be /src/misc/syslog.c
parent59549313d85fa9a0168ff8164cfe734255585f46 (diff)
downloadmusl-da27118157c2942d7652138b8d8b0056fc8f872f.tar.gz
musl-da27118157c2942d7652138b8d8b0056fc8f872f.tar.xz
musl-da27118157c2942d7652138b8d8b0056fc8f872f.zip
fix the %m specifier in syslog
errno must be saved upon vsyslog entry, otherwise its value could be
changed by some libc function before reaching the %m handler in
vsnprintf.
Diffstat (limited to 'src/misc/syslog.c')
-rw-r--r--src/misc/syslog.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/misc/syslog.c b/src/misc/syslog.c
index 1cd61ce4..57f1d75c 100644
--- a/src/misc/syslog.c
+++ b/src/misc/syslog.c
@@ -7,6 +7,7 @@
 #include <signal.h>
 #include <string.h>
 #include <pthread.h>
+#include <errno.h>
 #include "libc.h"
 #include "atomic.h"
 
@@ -76,6 +77,7 @@ static void _vsyslog(int priority, const char *message, va_list ap)
 	time_t now;
 	struct tm tm;
 	char buf[256];
+	int errno_save = errno;
 	int pid;
 	int l, l2;
 
@@ -93,6 +95,7 @@ static void _vsyslog(int priority, const char *message, va_list ap)
 	pid = (log_opt & LOG_PID) ? getpid() : 0;
 	l = snprintf(buf, sizeof buf, "<%d>%s %s%s%.0d%s: ",
 		priority, timebuf, log_ident, "["+!pid, pid, "]"+!pid);
+	errno = errno_save;
 	l2 = vsnprintf(buf+l, sizeof buf - l, message, ap);
 	if (l2 >= 0) {
 		if (l2 >= sizeof buf - l) l = sizeof buf - 1;