From 3c9e27f6957fb68b250c34b8e5fb7c8d6e0ce99f Mon Sep 17 00:00:00 2001 From: Marko Kreen Date: Mon, 19 Apr 2010 10:14:58 +0300 Subject: [PATCH] logging: avoid changing errno. So user can safely log syscall results without worrying about errno changing. --- usual/logging.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/usual/logging.c b/usual/logging.c index 36e34e4..db53e3b 100644 --- a/usual/logging.c +++ b/usual/logging.c @@ -101,11 +101,12 @@ void log_generic(enum LogLevel level, void *ctx, const char *fmt, ...) unsigned pid = getpid(); va_list ap; int pfxlen = 0; + int old_errno = errno; if (logging_prefix_cb) { pfxlen = logging_prefix_cb(level, ctx, buf, sizeof(buf)); if (pfxlen < 0) - return; + goto done; if (pfxlen >= (int)sizeof(buf)) pfxlen = sizeof(buf) - 1; } @@ -141,6 +142,9 @@ void log_generic(enum LogLevel level, void *ctx, const char *fmt, ...) start_syslog(); syslog(lev->syslog_prio, "%s", buf); } +done: + if (old_errno != errno) + errno = old_errno; } -- 2.39.5