From 8cccee36758b197739c2e8e46ed5e5eaea4b473c Mon Sep 17 00:00:00 2001 From: Marko Kreen Date: Mon, 19 Apr 2010 07:08:31 +0000 Subject: [PATCH] Dont let logging change errno. With badly configured logging and higher logging levels, the code can see wrong errno from syscalls. So always retore original errno when logging. --- src/util.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/util.c b/src/util.c index 1f4dd1e..eb9de5d 100644 --- a/src/util.c +++ b/src/util.c @@ -147,6 +147,7 @@ static void _log_write(const char *pfx, const char *msg) char buf[1024]; char tbuf[64]; int len; + int old_errno = errno; render_time(tbuf, sizeof(tbuf)); len = snprintf(buf, sizeof(buf), "%s %u %s %s\n", @@ -160,6 +161,9 @@ static void _log_write(const char *pfx, const char *msg) if (!cf_quiet) fprintf(stderr, "%s", buf); + + if (old_errno != errno) + errno = old_errno; } static void _log(const char *pfx, const char *fmt, va_list ap) -- 2.39.5