errno must be saved upon vsyslog entry, otherwise its value could be
changed by some libc function before reaching the %m handler in
vsnprintf.
(cherry picked from commit
da27118157c2942d7652138b8d8b0056fc8f872f)
#include <signal.h>
#include <string.h>
#include <pthread.h>
+#include <errno.h>
#include "libc.h"
#include "atomic.h"
time_t now;
struct tm tm;
char buf[256];
+ int errno_save = errno;
int pid;
int l, l2;
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;