summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYASUOKA Masahiko <yasuoka@cvs.openbsd.org>2019-03-31 03:53:43 +0000
committerYASUOKA Masahiko <yasuoka@cvs.openbsd.org>2019-03-31 03:53:43 +0000
commit2ecea199fd16b0697e1272b3fdd1eab85a449f39 (patch)
tree6b3875950fdc43afc2f0022d24de250e830dc52e
parentcf399edbc85b744450dfdb02b37efe37d1674cd6 (diff)
Save errno before doing other things. Also add __deade for fatal() and
fatalx().
-rw-r--r--usr.sbin/radiusd/log.c14
-rw-r--r--usr.sbin/radiusd/log.h6
2 files changed, 12 insertions, 8 deletions
diff --git a/usr.sbin/radiusd/log.c b/usr.sbin/radiusd/log.c
index 13bafcff588..048d82cc028 100644
--- a/usr.sbin/radiusd/log.c
+++ b/usr.sbin/radiusd/log.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.c,v 1.2 2017/03/29 18:01:51 bluhm Exp $ */
+/* $OpenBSD: log.c,v 1.3 2019/03/31 03:53:42 yasuoka Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -63,6 +63,7 @@ vlog(int pri, const char *fmt, va_list ap)
time_t curr;
struct tm tm;
u_int i = 0, j;
+ int saved_errno = errno;
static struct {
int v;
const char *l;
@@ -101,7 +102,8 @@ vlog(int pri, const char *fmt, va_list ap)
if (fmt[j] == '%' && fmt[j + 1] == 'm') {
++j;
fmtbuf[i] = '\0';
- strlcat(fmtbuf, strerror(errno), sizeof(fmtbuf) - 1);
+ strlcat(fmtbuf, strerror(saved_errno),
+ sizeof(fmtbuf) - 1);
i = strlen(fmtbuf);
} else
fmtbuf[i++] = fmt[j];
@@ -118,17 +120,19 @@ log_warn(const char *emsg, ...)
{
char *nfmt;
va_list ap;
+ int saved_errno = errno;
/* best effort to even work in out of memory situations */
if (emsg == NULL)
- logit(LOG_WARNING, "%s", strerror(errno));
+ logit(LOG_WARNING, "%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_WARNING, emsg, ap);
- logit(LOG_WARNING, "%s", strerror(errno));
+ logit(LOG_WARNING, "%s", strerror(saved_errno));
} else {
vlog(LOG_WARNING, nfmt, ap);
free(nfmt);
diff --git a/usr.sbin/radiusd/log.h b/usr.sbin/radiusd/log.h
index 11d62f749cc..66f1e80db82 100644
--- a/usr.sbin/radiusd/log.h
+++ b/usr.sbin/radiusd/log.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.h,v 1.1 2015/07/21 04:06:04 yasuoka Exp $ */
+/* $OpenBSD: log.h,v 1.2 2019/03/31 03:53:42 yasuoka Exp $ */
#ifndef _LOG_H
#define _LOG_H 1
@@ -22,8 +22,8 @@ void log_info(const char *, ...)
__attribute__((__format__ (printf, 1, 2)));
void log_debug(const char *, ...)
__attribute__((__format__ (printf, 1, 2)));
-void fatal(const char *);
-void fatalx(const char *);
+__dead void fatal(const char *);
+__dead void fatalx(const char *);
__END_DECLS
#endif