summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorSebastian Benoit <benno@cvs.openbsd.org>2017-01-20 23:29:59 +0000
committerSebastian Benoit <benno@cvs.openbsd.org>2017-01-20 23:29:59 +0000
commit99bff523d432619a0f3ef3ca1738e9c53aa57e13 (patch)
treebb45bd3823131d08b2a4565d3a9c431fb193c954 /usr.sbin
parent25774e4910f1b0e78708323c1199b52091f664c6 (diff)
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 florian@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/rtadvd/log.c29
-rw-r--r--usr.sbin/rtadvd/log.h35
-rw-r--r--usr.sbin/rtadvd/rtadvd.c6
3 files changed, 46 insertions, 24 deletions
diff --git a/usr.sbin/rtadvd/log.c b/usr.sbin/rtadvd/log.c
index 9b6c8980590..67638259098 100644
--- a/usr.sbin/rtadvd/log.c
+++ b/usr.sbin/rtadvd/log.c
@@ -1,3 +1,5 @@
+/* $OpenBSD: log.c,v 1.2 2017/01/20 23:29:58 benno Exp $ */
+
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@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 a/usr.sbin/rtadvd/log.h b/usr.sbin/rtadvd/log.h
index 0b005936327..479c21f34ed 100644
--- a/usr.sbin/rtadvd/log.h
+++ b/usr.sbin/rtadvd/log.h
@@ -1,5 +1,7 @@
+/* $OpenBSD: log.h,v 1.3 2017/01/20 23:29:58 benno Exp $ */
+
/*
- * Copyright (c) 20083, 2004 Henning Brauer <henning@openbsd.org>
+ * Copyright (c) 2003, 2004 Henning Brauer <henning@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 a/usr.sbin/rtadvd/rtadvd.c b/usr.sbin/rtadvd/rtadvd.c
index 990d9785c2d..aba081a6a84 100644
--- a/usr.sbin/rtadvd/rtadvd.c
+++ b/usr.sbin/rtadvd/rtadvd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rtadvd.c,v 1.82 2016/09/26 17:15:19 jca Exp $ */
+/* $OpenBSD: rtadvd.c,v 1.83 2017/01/20 23:29:58 benno Exp $ */
/* $KAME: rtadvd.c,v 1.66 2002/05/29 14:18:36 itojun Exp $ */
/*
@@ -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);