Browse Source

copy updated log.c from vmd: for correctness, save errno when doing

additional actions before printing it.  OK rzalamena@
OPENBSD_6_1
reyk 7 years ago
parent
commit
138484b6d2
1 changed files with 11 additions and 8 deletions
  1. +11
    -8
      src/usr.sbin/ntpd/log.c

+ 11
- 8
src/usr.sbin/ntpd/log.c View File

@ -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> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -109,19 +109,21 @@ vlog(int pri, const char *fmt, va_list ap)
void void
log_warn(const char *emsg, ...) 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 */ /* best effort to even work in out of memory situations */
if (emsg == NULL) if (emsg == NULL)
logit(LOG_CRIT, "%s", strerror(errno));
logit(LOG_CRIT, "%s", strerror(saved_errno));
else { else {
va_start(ap, emsg); 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... */ /* we tried it... */
vlog(LOG_CRIT, emsg, ap); vlog(LOG_CRIT, emsg, ap);
logit(LOG_CRIT, "%s", strerror(errno));
logit(LOG_CRIT, "%s", strerror(saved_errno));
} else { } else {
vlog(LOG_CRIT, nfmt, ap); vlog(LOG_CRIT, nfmt, ap);
free(nfmt); free(nfmt);
@ -167,6 +169,7 @@ vfatal(const char *emsg, va_list ap)
{ {
static char s[BUFSIZ]; static char s[BUFSIZ];
const char *sep; const char *sep;
int saved_errno = errno;
if (emsg != NULL) { if (emsg != NULL) {
(void)vsnprintf(s, sizeof(s), emsg, ap); (void)vsnprintf(s, sizeof(s), emsg, ap);
@ -175,9 +178,9 @@ vfatal(const char *emsg, va_list ap)
s[0] = '\0'; s[0] = '\0';
sep = ""; sep = "";
} }
if (errno)
if (saved_errno)
logit(LOG_CRIT, "%s: %s%s%s", logit(LOG_CRIT, "%s: %s%s%s",
log_procname, s, sep, strerror(errno));
log_procname, s, sep, strerror(saved_errno));
else else
logit(LOG_CRIT, "%s%s%s", log_procname, sep, s); logit(LOG_CRIT, "%s%s%s", log_procname, sep, s);
} }


Loading…
Cancel
Save