Skip to content

Commit

Permalink
logging: avoid changing errno.
Browse files Browse the repository at this point in the history
So user can safely log syscall results without worrying about errno changing.
  • Loading branch information
markokr committed Apr 27, 2010
1 parent 708225d commit 3c9e27f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion usual/logging.c
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}


Expand Down

0 comments on commit 3c9e27f

Please sign in to comment.