Permalink
Browse files

logging: avoid changing errno.

So user can safely log syscall results without worrying about errno changing.
  • Loading branch information...
1 parent 708225d commit 3c9e27f6957fb68b250c34b8e5fb7c8d6e0ce99f @markokr markokr committed Apr 19, 2010
Showing with 5 additions and 1 deletion.
  1. +5 −1 usual/logging.c
View
@@ -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;
}

0 comments on commit 3c9e27f

Please sign in to comment.