diff options
author | Ted Unangst <tedu@cvs.openbsd.org> | 2015-12-04 16:44:21 +0000 |
---|---|---|
committer | Ted Unangst <tedu@cvs.openbsd.org> | 2015-12-04 16:44:21 +0000 |
commit | 7d9f3c8095ec883454f29d6dbc6720032cac7a2d (patch) | |
tree | 04b8ff184176b72664537677dee194d672f1cb3c /usr.sbin | |
parent | 22cbaf65ac54a9764b7306ee4422d50a5c9ecf5d (diff) |
refine some logging and error messages. errors will now always go to stderr
until daemonized and syslog as well. make logerr() work more like err().
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/rebound/rebound.c | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/usr.sbin/rebound/rebound.c b/usr.sbin/rebound/rebound.c index e59973da7e3..27dda5d4c00 100644 --- a/usr.sbin/rebound/rebound.c +++ b/usr.sbin/rebound/rebound.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rebound.c,v 1.52 2015/12/04 16:33:40 tedu Exp $ */ +/* $OpenBSD: rebound.c,v 1.53 2015/12/04 16:44:20 tedu Exp $ */ /* * Copyright (c) 2015 Ted Unangst <tedu@openbsd.org> * @@ -41,6 +41,7 @@ uint16_t randomid(void); static struct timespec now; static int debug; +static int daemonized; struct dnspacket { uint16_t id; @@ -114,12 +115,11 @@ logmsg(int prio, const char *msg, ...) va_list ap; va_start(ap, msg); - if (debug) { + if (debug || !daemonized) { vfprintf(stderr, msg, ap); fprintf(stderr, "\n"); - } else { - vsyslog(LOG_DAEMON | prio, msg, ap); } + vsyslog(LOG_DAEMON | prio, msg, ap); va_end(ap); } @@ -129,12 +129,12 @@ logerr(const char *msg, ...) va_list ap; va_start(ap, msg); - if (debug) { + if (debug || !daemonized) { + fprintf(stderr, "rebound: "); vfprintf(stderr, msg, ap); fprintf(stderr, "\n"); - } else { - vsyslog(LOG_DAEMON | LOG_ERR, msg, ap); } + vsyslog(LOG_DAEMON | LOG_ERR, msg, ap); va_end(ap); exit(1); } @@ -654,10 +654,10 @@ main(int argc, char **argv) signal(SIGPIPE, SIG_IGN); if (getrlimit(RLIMIT_NOFILE, &rlim) == -1) - err(1, "getrlimit"); + logerr("getrlimit: %s", strerror(errno)); rlim.rlim_cur = rlim.rlim_max; if (setrlimit(RLIMIT_NOFILE, &rlim) == -1) - err(1, "setrlimit"); + logerr("setrlimit: %s", strerror(errno)); connmax = rlim.rlim_cur - 10; if (connmax > 512) connmax = 512; @@ -679,26 +679,28 @@ main(int argc, char **argv) ud = socket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK, 0); if (ud == -1) - err(1, "socket"); + logerr("socket: %s", strerror(errno)); if (bind(ud, (struct sockaddr *)&bindaddr, sizeof(bindaddr)) == -1) - err(1, "bind"); + logerr("bind: %s", strerror(errno)); ld = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0); if (ld == -1) - err(1, "socket"); + logerr("socket: %s", strerror(errno)); one = 1; setsockopt(ld, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); if (bind(ld, (struct sockaddr *)&bindaddr, sizeof(bindaddr)) == -1) - err(1, "bind"); + logerr("bind: %s", strerror(errno)); if (listen(ld, 10) == -1) - err(1, "listen"); + logerr("listen: %s", strerror(errno)); if (debug) { launch(conffile, ud, ld, -1); return 1; } - daemon(0, 0); + if (daemon(0, 0) == -1) + logerr("daemon: %s", strerror(errno)); + daemonized = 1; kq = kqueue(); |