work on making log.c similar in all daemons: reduce the (mostly whitespace) differences so that log.c's can be diffed easily.
need to set verbose in main() when option -d is used. ok? diff --git usr.sbin/rtadvd/log.c usr.sbin/rtadvd/log.c index 9b6c8980590..d3a5ba20727 100644 --- usr.sbin/rtadvd/log.c +++ usr.sbin/rtadvd/log.c @@ -1,3 +1,5 @@ +/* $OpenBSD: log.c,v 1.9 2016/09/02 14:02:48 benno Exp $ */ + /* * Copyright (c) 2003, 2004 Henning Brauer <henn...@openbsd.org> * @@ -14,9 +16,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include <err.h> #include <errno.h> -#include <netdb.h> #include <stdarg.h> #include <stdio.h> #include <stdlib.h> @@ -27,10 +27,9 @@ #include "log.h" -int debug; - -void logit(int, const char *, ...); -void vlog(int pri, const char *fmt, va_list ap); +int debug; +int verbose; +const char *log_procname; void log_init(int n_debug) @@ -46,6 +45,12 @@ log_init(int n_debug) } void +log_verbose(int v) +{ + verbose = v; +} + +void logit(int pri, const char *fmt, ...) { va_list ap; @@ -80,12 +85,12 @@ log_warn(const char *emsg, ...) char *nfmt; va_list ap; + /* best effort to even work in out of memory situations */ if (emsg == NULL) logit(LOG_CRIT, "%s", strerror(errno)); else { va_start(ap, emsg); - /* best effort to even work in out of memory situations */ if (asprintf(&nfmt, "%s: %s", emsg, strerror(errno)) == -1) { /* we tried it... */ vlog(LOG_CRIT, emsg, ap); @@ -123,7 +128,7 @@ log_debug(const char *emsg, ...) { va_list ap; - if (debug) { + if (verbose) { va_start(ap, emsg); vlog(LOG_DEBUG, emsg, ap); va_end(ap); @@ -133,18 +138,16 @@ log_debug(const char *emsg, ...) void fatal(const char *emsg) { - extern char *__progname; - if (emsg == NULL) - logit(LOG_CRIT, "fatal in %s: %s", __progname, + logit(LOG_CRIT, "fatal in %s: %s", log_procname, strerror(errno)); else if (errno) logit(LOG_CRIT, "fatal in %s: %s: %s", - __progname, emsg, strerror(errno)); + log_procname, emsg, strerror(errno)); else logit(LOG_CRIT, "fatal in %s: %s", - __progname, emsg); + log_procname, emsg); exit(1); } diff --git usr.sbin/rtadvd/log.h usr.sbin/rtadvd/log.h index 0b005936327..56f7b9246ac 100644 --- usr.sbin/rtadvd/log.h +++ usr.sbin/rtadvd/log.h @@ -1,5 +1,7 @@ +/* $OpenBSD: log.h,v 1.8 2016/09/02 14:02:48 benno Exp $ */ + /* - * Copyright (c) 20083, 2004 Henning Brauer <henn...@openbsd.org> + * Copyright (c) 2003, 2004 Henning Brauer <henn...@openbsd.org> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -14,15 +16,30 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#ifndef LOG_H +#define LOG_H + #include <stdarg.h> -void log_init(int); -void logit(int pri, const char *fmt, ...); +extern const char *log_procname; -__dead void fatal(const char*); -__dead void fatalx(const char*); +void log_init(int); +void log_verbose(int); +void logit(int, const char *, ...) + __attribute__((__format__ (printf, 2, 3))); +void vlog(int, const char *, va_list) + __attribute__((__format__ (printf, 2, 0))); +void log_warn(const char *, ...) + __attribute__((__format__ (printf, 1, 2))); +void log_warnx(const char *, ...) + __attribute__((__format__ (printf, 1, 2))); +void log_info(const char *, ...) + __attribute__((__format__ (printf, 1, 2))); +void log_debug(const char *, ...) + __attribute__((__format__ (printf, 1, 2))); +void fatal(const char *) __dead + __attribute__((__format__ (printf, 1, 0))); +void fatalx(const char *) __dead + __attribute__((__format__ (printf, 1, 0))); -void log_warn(const char*, ...) __attribute__((format(printf, 1, 2))); -void log_warnx(const char*, ...) __attribute__((format(printf, 1, 2))); -void log_info(const char*, ...) __attribute__((format(printf, 1, 2))); -void log_debug(const char*, ...) __attribute__((format(printf, 1, 2))); +#endif /* LOG_H */ diff --git usr.sbin/rtadvd/rtadvd.c usr.sbin/rtadvd/rtadvd.c index 990d9785c2d..eec7a177242 100644 --- usr.sbin/rtadvd/rtadvd.c +++ usr.sbin/rtadvd/rtadvd.c @@ -163,6 +163,7 @@ main(int argc, char *argv[]) struct event ev_sigusr1; struct rainfo *rai; + log_procname = getprogname(); log_init(1); /* log to stderr until daemonized */ closefrom(3); @@ -192,7 +193,8 @@ main(int argc, char *argv[]) devnull = open(_PATH_DEVNULL, O_RDWR, 0); if (devnull == -1) fatal("open(\"" _PATH_DEVNULL "\")"); - } + } else + log_verbose(1); SLIST_INIT(&ralist);