summaryrefslogtreecommitdiffstats
path: root/sbin/hastd
diff options
context:
space:
mode:
authorpjd <pjd@FreeBSD.org>2011-09-27 06:43:51 +0000
committerpjd <pjd@FreeBSD.org>2011-09-27 06:43:51 +0000
commite0053a0ea29eec7bce474cead8f81448fc39c005 (patch)
tree987387cb4da1abc6af87dc9656e4b085c251ea7d /sbin/hastd
parent07fff668ac842664d9d7a0f7e1bde4ffbec2d6d1 (diff)
downloadFreeBSD-src-e0053a0ea29eec7bce474cead8f81448fc39c005.zip
FreeBSD-src-e0053a0ea29eec7bce474cead8f81448fc39c005.tar.gz
Ensure that pjdlog functions don't modify errno.
MFC after: 3 days
Diffstat (limited to 'sbin/hastd')
-rw-r--r--sbin/hastd/pjdlog.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/sbin/hastd/pjdlog.c b/sbin/hastd/pjdlog.c
index 16ecf4d..bc4018f 100644
--- a/sbin/hastd/pjdlog.c
+++ b/sbin/hastd/pjdlog.c
@@ -148,11 +148,14 @@ pjdlog_printf_render_sockaddr(struct __printf_io *io,
void
pjdlog_init(int mode)
{
+ int saved_errno;
assert(pjdlog_initialized == PJDLOG_NEVER_INITIALIZED ||
pjdlog_initialized == PJDLOG_NOT_INITIALIZED);
assert(mode == PJDLOG_MODE_STD || mode == PJDLOG_MODE_SYSLOG);
+ saved_errno = errno;
+
if (pjdlog_initialized == PJDLOG_NEVER_INITIALIZED) {
__use_xprintf = 1;
register_printf_render_std("T");
@@ -171,18 +174,25 @@ pjdlog_init(int mode)
bzero(pjdlog_prefix, sizeof(pjdlog_prefix));
pjdlog_initialized = PJDLOG_INITIALIZED;
+
+ errno = saved_errno;
}
void
pjdlog_fini(void)
{
+ int saved_errno;
assert(pjdlog_initialized == PJDLOG_INITIALIZED);
+ saved_errno = errno;
+
if (pjdlog_mode == PJDLOG_MODE_SYSLOG)
closelog();
pjdlog_initialized = PJDLOG_NOT_INITIALIZED;
+
+ errno = saved_errno;
}
/*
@@ -194,6 +204,7 @@ pjdlog_fini(void)
void
pjdlog_mode_set(int mode)
{
+ int saved_errno;
assert(pjdlog_initialized == PJDLOG_INITIALIZED);
assert(mode == PJDLOG_MODE_STD || mode == PJDLOG_MODE_SYSLOG);
@@ -201,12 +212,16 @@ pjdlog_mode_set(int mode)
if (pjdlog_mode == mode)
return;
+ saved_errno = errno;
+
if (mode == PJDLOG_MODE_SYSLOG)
openlog(NULL, LOG_PID | LOG_NDELAY, LOG_DAEMON);
else /* if (mode == PJDLOG_MODE_STD) */
closelog();
pjdlog_mode = mode;
+
+ errno = saved_errno;
}
/*
@@ -270,11 +285,16 @@ pjdlog_prefix_set(const char *fmt, ...)
void
pjdlogv_prefix_set(const char *fmt, va_list ap)
{
+ int saved_errno;
assert(pjdlog_initialized == PJDLOG_INITIALIZED);
assert(fmt != NULL);
+ saved_errno = errno;
+
vsnprintf(pjdlog_prefix, sizeof(pjdlog_prefix), fmt, ap);
+
+ errno = saved_errno;
}
/*
@@ -329,6 +349,7 @@ void
pjdlogv_common(int loglevel, int debuglevel, int error, const char *fmt,
va_list ap)
{
+ int saved_errno;
assert(pjdlog_initialized == PJDLOG_INITIALIZED);
assert(loglevel == LOG_EMERG || loglevel == LOG_ALERT ||
@@ -342,6 +363,8 @@ pjdlogv_common(int loglevel, int debuglevel, int error, const char *fmt,
if (loglevel == LOG_DEBUG && debuglevel > pjdlog_debug_level)
return;
+ saved_errno = errno;
+
switch (pjdlog_mode) {
case PJDLOG_MODE_STD:
{
@@ -398,6 +421,8 @@ pjdlogv_common(int loglevel, int debuglevel, int error, const char *fmt,
default:
assert(!"Invalid mode.");
}
+
+ errno = saved_errno;
}
/*
OpenPOWER on IntegriCloud