diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2003-12-26 16:48:08 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2003-12-26 16:48:08 +0000 |
commit | 3c819e3182e49fcdf4bb61f4eb711fc0312c0d42 (patch) | |
tree | 909e30f6b1d97ef0ce40308b454577d6dd666639 | |
parent | 96b2b4524d5506a4dbafe845a5944e11739e6a2b (diff) |
provide a real log_err
-rw-r--r-- | usr.sbin/bgpd/bgpd.h | 3 | ||||
-rw-r--r-- | usr.sbin/bgpd/kroute.c | 8 | ||||
-rw-r--r-- | usr.sbin/bgpd/log.c | 25 |
3 files changed, 30 insertions, 6 deletions
diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h index 3c471413af7..a8db8800242 100644 --- a/usr.sbin/bgpd/bgpd.h +++ b/usr.sbin/bgpd/bgpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.h,v 1.35 2003/12/26 16:37:04 henning Exp $ */ +/* $OpenBSD: bgpd.h,v 1.36 2003/12/26 16:48:07 henning Exp $ */ /* * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> @@ -281,6 +281,7 @@ void logit(int, const char *, ...); void vlog(int, const char *, va_list); void log_peer_err(struct peer *, const char *, ...); void log_peer_errx(struct peer *, const char *, ...); +void log_err(const char *, ...); void fatal(const char *, int); void fatal_ensure(const char *, int, const char *); void log_statechange(struct peer *, enum session_state, diff --git a/usr.sbin/bgpd/kroute.c b/usr.sbin/bgpd/kroute.c index 18dae13ff9d..ec11480aa3b 100644 --- a/usr.sbin/bgpd/kroute.c +++ b/usr.sbin/bgpd/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.29 2003/12/26 15:42:14 henning Exp $ */ +/* $OpenBSD: kroute.c,v 1.30 2003/12/26 16:48:07 henning Exp $ */ /* * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> @@ -81,12 +81,12 @@ kroute_init(void) { int s, opt; - if ((s = socket(AF_ROUTE, SOCK_RAW, 0)) < 0) - fatal("route socket", errno); + if ((s = socket(AF_ROUTE, SOCK_RAW, 0)) == -1) + return (-1); /* not intrested in my own messages */ if (setsockopt(s, SOL_SOCKET, SO_USELOOPBACK, &opt, sizeof(opt)) == -1) - fatal("route setsockopt", errno); + return (-1); pid = getpid(); diff --git a/usr.sbin/bgpd/log.c b/usr.sbin/bgpd/log.c index a229c20259d..3128848f022 100644 --- a/usr.sbin/bgpd/log.c +++ b/usr.sbin/bgpd/log.c @@ -1,4 +1,4 @@ -/* $OpenBSD: log.c,v 1.8 2003/12/26 16:37:04 henning Exp $ */ +/* $OpenBSD: log.c,v 1.9 2003/12/26 16:48:07 henning Exp $ */ /* * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> @@ -196,6 +196,29 @@ log_peer_errx(struct peer *peer, const char *emsg, ...) } void +log_err(const char *emsg, ...) +{ + char *nfmt; + va_list ap; + + /* best effort to even work in out of memory situations */ + + va_start(ap, emsg); + + if (emsg == NULL) + logit(LOG_CRIT, "%s", strerror(errno)); + else { + if (asprintf(&nfmt, "%s: %s", emsg, strerror(errno)) == -1) { + /* we tried it... */ + vlog(LOG_CRIT, emsg, ap); + logit(LOG_CRIT, "%s", strerror(errno)); + } else + vlog(LOG_CRIT, nfmt, ap); + } + va_end(ap); +} + +void fatal(const char *emsg, int error) { if (emsg == NULL) |