summaryrefslogtreecommitdiffstats
path: root/lib/libc/gen/syslog_r.c
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>2016-10-19 16:09:24 +0000
committermillert <millert@openbsd.org>2016-10-19 16:09:24 +0000
commit6ac5adf8471ec1c4d2d0eccf88866b4654fddb19 (patch)
treed26b241c8533048ade0f027ca893a5633e152f35 /lib/libc/gen/syslog_r.c
parentThe clean:, cleandir:, and obj: targets of src/Makefile descend into (diff)
downloadwireguard-openbsd-6ac5adf8471ec1c4d2d0eccf88866b4654fddb19.tar.xz
wireguard-openbsd-6ac5adf8471ec1c4d2d0eccf88866b4654fddb19.zip
Use the reentrant strerror_r() instead of strerror() to expand %m.
Previously, syslog_r() would avoid calling strerror() since the latter is not reentrant. OK bluhm@
Diffstat (limited to 'lib/libc/gen/syslog_r.c')
-rw-r--r--lib/libc/gen/syslog_r.c15
1 files changed, 5 insertions, 10 deletions
diff --git a/lib/libc/gen/syslog_r.c b/lib/libc/gen/syslog_r.c
index 75a3ac84704..2bc6e4437aa 100644
--- a/lib/libc/gen/syslog_r.c
+++ b/lib/libc/gen/syslog_r.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: syslog_r.c,v 1.15 2016/03/27 16:28:56 chl Exp $ */
+/* $OpenBSD: syslog_r.c,v 1.16 2016/10/19 16:09:24 millert Exp $ */
/*
* Copyright (c) 1983, 1988, 1993
* The Regents of the University of California. All rights reserved.
@@ -138,18 +138,13 @@ __vsyslog_r(int pri, struct syslog_data *data,
}
}
- /* strerror() is not reentrant */
-
for (t = fmt_cpy, fmt_left = FMT_LEN; (ch = *fmt); ++fmt) {
if (ch == '%' && fmt[1] == 'm') {
+ char ebuf[NL_TEXTMAX];
+
++fmt;
- if (reentrant) {
- prlen = snprintf(t, fmt_left, "Error %d",
- saved_errno);
- } else {
- prlen = snprintf(t, fmt_left, "%s",
- strerror(saved_errno));
- }
+ (void)strerror_r(saved_errno, ebuf, sizeof(ebuf));
+ prlen = snprintf(t, fmt_left, "%s", ebuf);
if (prlen < 0)
prlen = 0;
if (prlen >= fmt_left)