diff options
author | 2004-01-19 23:15:08 +0000 | |
---|---|---|
committer | 2004-01-19 23:15:08 +0000 | |
commit | 1f975a75a05546ee517d9730b38df025652032c5 (patch) | |
tree | 933aa87fede9530a122edc17f4b246e9e06e1e59 | |
parent | fix mem leaks; some fixes from Pete Flugstad; tested dtucker@ (diff) | |
download | wireguard-openbsd-1f975a75a05546ee517d9730b38df025652032c5.tar.xz wireguard-openbsd-1f975a75a05546ee517d9730b38df025652032c5.zip |
(v)fprintf atomically in vlog() in debug mode, prodded by theo
-rw-r--r-- | usr.sbin/bgpd/log.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/usr.sbin/bgpd/log.c b/usr.sbin/bgpd/log.c index c377b95364c..d3557e0335a 100644 --- a/usr.sbin/bgpd/log.c +++ b/usr.sbin/bgpd/log.c @@ -1,4 +1,4 @@ -/* $OpenBSD: log.c,v 1.15 2004/01/06 03:43:50 henning Exp $ */ +/* $OpenBSD: log.c,v 1.16 2004/01/19 23:15:08 henning Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -142,9 +142,17 @@ logit(int pri, const char *fmt, ...) void vlog(int pri, const char *fmt, va_list ap) { + char *nfmt; + if (debug) { - vfprintf(stderr, fmt, ap); - fprintf(stderr, "\n"); + /* best effort in out of mem situations */ + if (asprintf(&nfmt, "%s\n", fmt) == -1) { + vfprintf(stderr, fmt, ap); + fprintf(stderr, "\n"); + } else { + vfprintf(stderr, nfmt, ap); + free(nfmt); + } } else vsyslog(pri, fmt, ap); } |