summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorreyk <reyk@openbsd.org>2016-10-12 11:57:31 +0000
committerreyk <reyk@openbsd.org>2016-10-12 11:57:31 +0000
commita6bfe15747f1d593b5cd658df9cd3cd8ffcb8f1a (patch)
tree670b985e5039627f87380b7291dfebc180df89c3
parentFor correctness, always save errno when doing additional actions (diff)
downloadwireguard-openbsd-a6bfe15747f1d593b5cd658df9cd3cd8ffcb8f1a.tar.xz
wireguard-openbsd-a6bfe15747f1d593b5cd658df9cd3cd8ffcb8f1a.zip
copy updated log.c from vmd: for correctness, save errno when doing
additional actions before printing it. OK rzalamena@
-rw-r--r--sbin/iked/log.c19
-rw-r--r--usr.sbin/httpd/log.c19
-rw-r--r--usr.sbin/ntpd/log.c19
-rw-r--r--usr.sbin/relayd/log.c19
-rw-r--r--usr.sbin/snmpd/log.c19
-rw-r--r--usr.sbin/switchd/log.c19
6 files changed, 66 insertions, 48 deletions
diff --git a/sbin/iked/log.c b/sbin/iked/log.c
index 7b1783b4a32..b581ab1b3de 100644
--- a/sbin/iked/log.c
+++ b/sbin/iked/log.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.c,v 1.8 2015/12/07 12:13:51 reyk Exp $ */
+/* $OpenBSD: log.c,v 1.9 2016/10/12 11:57:31 reyk Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -109,19 +109,21 @@ vlog(int pri, const char *fmt, va_list ap)
void
log_warn(const char *emsg, ...)
{
- char *nfmt;
- va_list ap;
+ char *nfmt;
+ va_list ap;
+ int saved_errno = errno;
/* best effort to even work in out of memory situations */
if (emsg == NULL)
- logit(LOG_CRIT, "%s", strerror(errno));
+ logit(LOG_CRIT, "%s", strerror(saved_errno));
else {
va_start(ap, emsg);
- if (asprintf(&nfmt, "%s: %s", emsg, strerror(errno)) == -1) {
+ if (asprintf(&nfmt, "%s: %s", emsg,
+ strerror(saved_errno)) == -1) {
/* we tried it... */
vlog(LOG_CRIT, emsg, ap);
- logit(LOG_CRIT, "%s", strerror(errno));
+ logit(LOG_CRIT, "%s", strerror(saved_errno));
} else {
vlog(LOG_CRIT, nfmt, ap);
free(nfmt);
@@ -167,6 +169,7 @@ vfatal(const char *emsg, va_list ap)
{
static char s[BUFSIZ];
const char *sep;
+ int saved_errno = errno;
if (emsg != NULL) {
(void)vsnprintf(s, sizeof(s), emsg, ap);
@@ -175,9 +178,9 @@ vfatal(const char *emsg, va_list ap)
s[0] = '\0';
sep = "";
}
- if (errno)
+ if (saved_errno)
logit(LOG_CRIT, "%s: %s%s%s",
- log_procname, s, sep, strerror(errno));
+ log_procname, s, sep, strerror(saved_errno));
else
logit(LOG_CRIT, "%s%s%s", log_procname, sep, s);
}
diff --git a/usr.sbin/httpd/log.c b/usr.sbin/httpd/log.c
index 1f6ff49c8e9..581191f0c09 100644
--- a/usr.sbin/httpd/log.c
+++ b/usr.sbin/httpd/log.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.c,v 1.10 2015/12/07 12:13:51 reyk Exp $ */
+/* $OpenBSD: log.c,v 1.11 2016/10/12 11:57:31 reyk Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -109,19 +109,21 @@ vlog(int pri, const char *fmt, va_list ap)
void
log_warn(const char *emsg, ...)
{
- char *nfmt;
- va_list ap;
+ char *nfmt;
+ va_list ap;
+ int saved_errno = errno;
/* best effort to even work in out of memory situations */
if (emsg == NULL)
- logit(LOG_CRIT, "%s", strerror(errno));
+ logit(LOG_CRIT, "%s", strerror(saved_errno));
else {
va_start(ap, emsg);
- if (asprintf(&nfmt, "%s: %s", emsg, strerror(errno)) == -1) {
+ if (asprintf(&nfmt, "%s: %s", emsg,
+ strerror(saved_errno)) == -1) {
/* we tried it... */
vlog(LOG_CRIT, emsg, ap);
- logit(LOG_CRIT, "%s", strerror(errno));
+ logit(LOG_CRIT, "%s", strerror(saved_errno));
} else {
vlog(LOG_CRIT, nfmt, ap);
free(nfmt);
@@ -167,6 +169,7 @@ vfatal(const char *emsg, va_list ap)
{
static char s[BUFSIZ];
const char *sep;
+ int saved_errno = errno;
if (emsg != NULL) {
(void)vsnprintf(s, sizeof(s), emsg, ap);
@@ -175,9 +178,9 @@ vfatal(const char *emsg, va_list ap)
s[0] = '\0';
sep = "";
}
- if (errno)
+ if (saved_errno)
logit(LOG_CRIT, "%s: %s%s%s",
- log_procname, s, sep, strerror(errno));
+ log_procname, s, sep, strerror(saved_errno));
else
logit(LOG_CRIT, "%s%s%s", log_procname, sep, s);
}
diff --git a/usr.sbin/ntpd/log.c b/usr.sbin/ntpd/log.c
index 5b35b33ef3b..52df59c0e42 100644
--- a/usr.sbin/ntpd/log.c
+++ b/usr.sbin/ntpd/log.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.c,v 1.13 2015/12/19 17:55:29 reyk Exp $ */
+/* $OpenBSD: log.c,v 1.14 2016/10/12 11:57:31 reyk Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -109,19 +109,21 @@ vlog(int pri, const char *fmt, va_list ap)
void
log_warn(const char *emsg, ...)
{
- char *nfmt;
- va_list ap;
+ char *nfmt;
+ va_list ap;
+ int saved_errno = errno;
/* best effort to even work in out of memory situations */
if (emsg == NULL)
- logit(LOG_CRIT, "%s", strerror(errno));
+ logit(LOG_CRIT, "%s", strerror(saved_errno));
else {
va_start(ap, emsg);
- if (asprintf(&nfmt, "%s: %s", emsg, strerror(errno)) == -1) {
+ if (asprintf(&nfmt, "%s: %s", emsg,
+ strerror(saved_errno)) == -1) {
/* we tried it... */
vlog(LOG_CRIT, emsg, ap);
- logit(LOG_CRIT, "%s", strerror(errno));
+ logit(LOG_CRIT, "%s", strerror(saved_errno));
} else {
vlog(LOG_CRIT, nfmt, ap);
free(nfmt);
@@ -167,6 +169,7 @@ vfatal(const char *emsg, va_list ap)
{
static char s[BUFSIZ];
const char *sep;
+ int saved_errno = errno;
if (emsg != NULL) {
(void)vsnprintf(s, sizeof(s), emsg, ap);
@@ -175,9 +178,9 @@ vfatal(const char *emsg, va_list ap)
s[0] = '\0';
sep = "";
}
- if (errno)
+ if (saved_errno)
logit(LOG_CRIT, "%s: %s%s%s",
- log_procname, s, sep, strerror(errno));
+ log_procname, s, sep, strerror(saved_errno));
else
logit(LOG_CRIT, "%s%s%s", log_procname, sep, s);
}
diff --git a/usr.sbin/relayd/log.c b/usr.sbin/relayd/log.c
index 35f1bb8a7c2..b43a6eb9382 100644
--- a/usr.sbin/relayd/log.c
+++ b/usr.sbin/relayd/log.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.c,v 1.31 2015/12/07 12:13:51 reyk Exp $ */
+/* $OpenBSD: log.c,v 1.32 2016/10/12 11:57:31 reyk Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -109,19 +109,21 @@ vlog(int pri, const char *fmt, va_list ap)
void
log_warn(const char *emsg, ...)
{
- char *nfmt;
- va_list ap;
+ char *nfmt;
+ va_list ap;
+ int saved_errno = errno;
/* best effort to even work in out of memory situations */
if (emsg == NULL)
- logit(LOG_CRIT, "%s", strerror(errno));
+ logit(LOG_CRIT, "%s", strerror(saved_errno));
else {
va_start(ap, emsg);
- if (asprintf(&nfmt, "%s: %s", emsg, strerror(errno)) == -1) {
+ if (asprintf(&nfmt, "%s: %s", emsg,
+ strerror(saved_errno)) == -1) {
/* we tried it... */
vlog(LOG_CRIT, emsg, ap);
- logit(LOG_CRIT, "%s", strerror(errno));
+ logit(LOG_CRIT, "%s", strerror(saved_errno));
} else {
vlog(LOG_CRIT, nfmt, ap);
free(nfmt);
@@ -167,6 +169,7 @@ vfatal(const char *emsg, va_list ap)
{
static char s[BUFSIZ];
const char *sep;
+ int saved_errno = errno;
if (emsg != NULL) {
(void)vsnprintf(s, sizeof(s), emsg, ap);
@@ -175,9 +178,9 @@ vfatal(const char *emsg, va_list ap)
s[0] = '\0';
sep = "";
}
- if (errno)
+ if (saved_errno)
logit(LOG_CRIT, "%s: %s%s%s",
- log_procname, s, sep, strerror(errno));
+ log_procname, s, sep, strerror(saved_errno));
else
logit(LOG_CRIT, "%s%s%s", log_procname, sep, s);
}
diff --git a/usr.sbin/snmpd/log.c b/usr.sbin/snmpd/log.c
index ae5dc9bf721..dd15b28c6c7 100644
--- a/usr.sbin/snmpd/log.c
+++ b/usr.sbin/snmpd/log.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.c,v 1.12 2015/12/07 12:13:51 reyk Exp $ */
+/* $OpenBSD: log.c,v 1.13 2016/10/12 11:57:31 reyk Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -109,19 +109,21 @@ vlog(int pri, const char *fmt, va_list ap)
void
log_warn(const char *emsg, ...)
{
- char *nfmt;
- va_list ap;
+ char *nfmt;
+ va_list ap;
+ int saved_errno = errno;
/* best effort to even work in out of memory situations */
if (emsg == NULL)
- logit(LOG_CRIT, "%s", strerror(errno));
+ logit(LOG_CRIT, "%s", strerror(saved_errno));
else {
va_start(ap, emsg);
- if (asprintf(&nfmt, "%s: %s", emsg, strerror(errno)) == -1) {
+ if (asprintf(&nfmt, "%s: %s", emsg,
+ strerror(saved_errno)) == -1) {
/* we tried it... */
vlog(LOG_CRIT, emsg, ap);
- logit(LOG_CRIT, "%s", strerror(errno));
+ logit(LOG_CRIT, "%s", strerror(saved_errno));
} else {
vlog(LOG_CRIT, nfmt, ap);
free(nfmt);
@@ -167,6 +169,7 @@ vfatal(const char *emsg, va_list ap)
{
static char s[BUFSIZ];
const char *sep;
+ int saved_errno = errno;
if (emsg != NULL) {
(void)vsnprintf(s, sizeof(s), emsg, ap);
@@ -175,9 +178,9 @@ vfatal(const char *emsg, va_list ap)
s[0] = '\0';
sep = "";
}
- if (errno)
+ if (saved_errno)
logit(LOG_CRIT, "%s: %s%s%s",
- log_procname, s, sep, strerror(errno));
+ log_procname, s, sep, strerror(saved_errno));
else
logit(LOG_CRIT, "%s%s%s", log_procname, sep, s);
}
diff --git a/usr.sbin/switchd/log.c b/usr.sbin/switchd/log.c
index ecd94e44674..eb436e4fb62 100644
--- a/usr.sbin/switchd/log.c
+++ b/usr.sbin/switchd/log.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.c,v 1.1 2016/07/19 16:54:26 reyk Exp $ */
+/* $OpenBSD: log.c,v 1.2 2016/10/12 11:57:31 reyk Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -109,19 +109,21 @@ vlog(int pri, const char *fmt, va_list ap)
void
log_warn(const char *emsg, ...)
{
- char *nfmt;
- va_list ap;
+ char *nfmt;
+ va_list ap;
+ int saved_errno = errno;
/* best effort to even work in out of memory situations */
if (emsg == NULL)
- logit(LOG_CRIT, "%s", strerror(errno));
+ logit(LOG_CRIT, "%s", strerror(saved_errno));
else {
va_start(ap, emsg);
- if (asprintf(&nfmt, "%s: %s", emsg, strerror(errno)) == -1) {
+ if (asprintf(&nfmt, "%s: %s", emsg,
+ strerror(saved_errno)) == -1) {
/* we tried it... */
vlog(LOG_CRIT, emsg, ap);
- logit(LOG_CRIT, "%s", strerror(errno));
+ logit(LOG_CRIT, "%s", strerror(saved_errno));
} else {
vlog(LOG_CRIT, nfmt, ap);
free(nfmt);
@@ -167,6 +169,7 @@ vfatal(const char *emsg, va_list ap)
{
static char s[BUFSIZ];
const char *sep;
+ int saved_errno = errno;
if (emsg != NULL) {
(void)vsnprintf(s, sizeof(s), emsg, ap);
@@ -175,9 +178,9 @@ vfatal(const char *emsg, va_list ap)
s[0] = '\0';
sep = "";
}
- if (errno)
+ if (saved_errno)
logit(LOG_CRIT, "%s: %s%s%s",
- log_procname, s, sep, strerror(errno));
+ log_procname, s, sep, strerror(saved_errno));
else
logit(LOG_CRIT, "%s%s%s", log_procname, sep, s);
}