summaryrefslogtreecommitdiff
path: root/usr.sbin/ospf6d
diff options
context:
space:
mode:
authorSebastian Benoit <benno@cvs.openbsd.org>2017-08-12 16:27:51 +0000
committerSebastian Benoit <benno@cvs.openbsd.org>2017-08-12 16:27:51 +0000
commit6cc55c5464535c5afae9ecff4fe7c7a6075c78b2 (patch)
treef0d7be5ccfbd8113db6a0ab260dd46b1f6c4d0fc /usr.sbin/ospf6d
parentf4a53974ba2be37efae9135536142265c527714b (diff)
bring ospf6d's log.c in sync with ospfd and bgpd
ok florian@ claudio@
Diffstat (limited to 'usr.sbin/ospf6d')
-rw-r--r--usr.sbin/ospf6d/control.c4
-rw-r--r--usr.sbin/ospf6d/log.c98
-rw-r--r--usr.sbin/ospf6d/log.h42
-rw-r--r--usr.sbin/ospf6d/ospf6d.c17
-rw-r--r--usr.sbin/ospf6d/ospf6d.h3
-rw-r--r--usr.sbin/ospf6d/ospfe.c10
-rw-r--r--usr.sbin/ospf6d/rde.c12
7 files changed, 116 insertions, 70 deletions
diff --git a/usr.sbin/ospf6d/control.c b/usr.sbin/ospf6d/control.c
index 890b6615e47..29bb254f0f2 100644
--- a/usr.sbin/ospf6d/control.c
+++ b/usr.sbin/ospf6d/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.25 2017/01/08 23:04:42 krw Exp $ */
+/* $OpenBSD: control.c,v 1.26 2017/08/12 16:27:50 benno Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -298,7 +298,7 @@ control_dispatch_imsg(int fd, short event, void *bula)
imsg.data, imsg.hdr.len - IMSG_HEADER_SIZE);
memcpy(&verbose, imsg.data, sizeof(verbose));
- log_verbose(verbose);
+ log_setverbose(verbose);
break;
default:
log_debug("control_dispatch_imsg: "
diff --git a/usr.sbin/ospf6d/log.c b/usr.sbin/ospf6d/log.c
index 4062a883766..3f0b74e8d98 100644
--- a/usr.sbin/ospf6d/log.c
+++ b/usr.sbin/ospf6d/log.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.c,v 1.14 2017/03/21 12:06:56 bluhm Exp $ */
+/* $OpenBSD: log.c,v 1.15 2017/08/12 16:27:50 benno Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -16,40 +16,54 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <errno.h>
-#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdarg.h>
#include <string.h>
#include <syslog.h>
+#include <errno.h>
#include <time.h>
#include "log.h"
-#include "ospf6d.h"
-int debug;
-int verbose;
-const char *log_procname;
+static int debug;
+static int verbose;
+static const char *log_procname;
void
-log_init(int n_debug)
+log_init(int n_debug, int facility)
{
extern char *__progname;
debug = n_debug;
+ verbose = n_debug;
+ log_procinit(__progname);
if (!debug)
- openlog(__progname, LOG_PID | LOG_NDELAY, LOG_DAEMON);
+ openlog(__progname, LOG_PID | LOG_NDELAY, facility);
tzset();
}
void
-log_verbose(int v)
+log_procinit(const char *procname)
+{
+ if (procname != NULL)
+ log_procname = procname;
+}
+
+void
+log_setverbose(int v)
{
verbose = v;
}
+int
+log_getverbose(void)
+{
+ return (verbose);
+}
+
void
logit(int pri, const char *fmt, ...)
{
@@ -64,6 +78,7 @@ void
vlog(int pri, const char *fmt, va_list ap)
{
char *nfmt;
+ int saved_errno = errno;
if (debug) {
/* best effort in out of mem situations */
@@ -77,30 +92,36 @@ vlog(int pri, const char *fmt, va_list ap)
fflush(stderr);
} else
vsyslog(pri, fmt, ap);
+
+ errno = saved_errno;
}
void
log_warn(const char *emsg, ...)
{
- char *nfmt;
- va_list ap;
+ char *nfmt;
+ va_list ap;
+ int saved_errno = errno;
/* best effort to even work in out of memory situations */
if (emsg == NULL)
- logit(LOG_ERR, "%s", strerror(errno));
+ logit(LOG_ERR, "%s", strerror(saved_errno));
else {
va_start(ap, emsg);
- if (asprintf(&nfmt, "%s: %s", emsg, strerror(errno)) == -1) {
+ if (asprintf(&nfmt, "%s: %s", emsg,
+ strerror(saved_errno)) == -1) {
/* we tried it... */
vlog(LOG_ERR, emsg, ap);
- logit(LOG_ERR, "%s", strerror(errno));
+ logit(LOG_ERR, "%s", strerror(saved_errno));
} else {
vlog(LOG_ERR, nfmt, ap);
free(nfmt);
}
va_end(ap);
}
+
+ errno = saved_errno;
}
void
@@ -135,33 +156,44 @@ log_debug(const char *emsg, ...)
}
}
+static void
+vfatalc(int code, const char *emsg, va_list ap)
+{
+ static char s[BUFSIZ];
+ const char *sep;
+
+ if (emsg != NULL) {
+ (void)vsnprintf(s, sizeof(s), emsg, ap);
+ sep = ": ";
+ } else {
+ s[0] = '\0';
+ sep = "";
+ }
+ if (code)
+ logit(LOG_CRIT, "fatal in %s: %s%s%s",
+ log_procname, s, sep, strerror(code));
+ else
+ logit(LOG_CRIT, "fatal in %s%s%s", log_procname, sep, s);
+}
+
void
fatal(const char *emsg, ...)
{
- char s[1024];
- va_list ap;
+ va_list ap;
va_start(ap, emsg);
- vsnprintf(s, sizeof(s), emsg, ap);
+ vfatalc(errno, emsg, ap);
va_end(ap);
-
- if (emsg == NULL)
- logit(LOG_CRIT, "fatal in %s: %s", log_procname,
- strerror(errno));
- else
- if (errno)
- logit(LOG_CRIT, "fatal in %s: %s: %s",
- log_procname, s, strerror(errno));
- else
- logit(LOG_CRIT, "fatal in %s: %s",
- log_procname, s);
-
exit(1);
}
void
-fatalx(const char *emsg)
+fatalx(const char *emsg, ...)
{
- errno = 0;
- fatal(emsg);
+ va_list ap;
+
+ va_start(ap, emsg);
+ vfatalc(0, emsg, ap);
+ va_end(ap);
+ exit(1);
}
diff --git a/usr.sbin/ospf6d/log.h b/usr.sbin/ospf6d/log.h
index 1745e8282d0..a29cc7d7adc 100644
--- a/usr.sbin/ospf6d/log.h
+++ b/usr.sbin/ospf6d/log.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.h,v 1.11 2017/01/23 08:41:02 benno Exp $ */
+/* $OpenBSD: log.h,v 1.12 2017/08/12 16:27:50 benno Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -22,25 +22,25 @@
#include <stdarg.h>
#include <sys/cdefs.h>
-extern const char *log_procname;
-
-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, 2)));
-void fatalx(const char *) __dead
- __attribute__((__format__ (printf, 1, 0)));
+void log_init(int, int);
+void log_procinit(const char *);
+void log_setverbose(int);
+int log_getverbose(void);
+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 logit(int, const char *, ...)
+ __attribute__((__format__ (printf, 2, 3)));
+void vlog(int, const char *, va_list)
+ __attribute__((__format__ (printf, 2, 0)));
+__dead void fatal(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+__dead void fatalx(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
#endif /* LOG_H */
diff --git a/usr.sbin/ospf6d/ospf6d.c b/usr.sbin/ospf6d/ospf6d.c
index e7cc2de4f95..b4601e5272b 100644
--- a/usr.sbin/ospf6d/ospf6d.c
+++ b/usr.sbin/ospf6d/ospf6d.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ospf6d.c,v 1.33 2017/05/30 12:42:31 friehm Exp $ */
+/* $OpenBSD: ospf6d.c,v 1.34 2017/08/12 16:27:50 benno Exp $ */
/*
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -25,6 +25,7 @@
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/sysctl.h>
+#include <syslog.h>
#include <netinet/in.h>
#include <arpa/inet.h>
@@ -116,11 +117,11 @@ main(int argc, char *argv[])
conffile = CONF_FILE;
ospfd_process = PROC_MAIN;
- log_procname = log_procnames[ospfd_process];
sockname = OSPF6D_SOCKET;
- log_init(1); /* log to stderr until daemonized */
- log_verbose(1);
+ log_init(1, LOG_DAEMON); /* log to stderr until daemonized */
+ log_procinit(log_procnames[ospfd_process]);
+ log_setverbose(1);
while ((ch = getopt(argc, argv, "cdD:f:s:nv")) != -1) {
switch (ch) {
@@ -148,7 +149,7 @@ main(int argc, char *argv[])
if (opts & OSPFD_OPT_VERBOSE)
opts |= OSPFD_OPT_VERBOSE2;
opts |= OSPFD_OPT_VERBOSE;
- log_verbose(1);
+ log_setverbose(1);
break;
default:
usage();
@@ -199,8 +200,8 @@ main(int argc, char *argv[])
if (getpwnam(OSPF6D_USER) == NULL)
errx(1, "unknown user %s", OSPF6D_USER);
- log_init(debug);
- log_verbose(ospfd_conf->opts & OSPFD_OPT_VERBOSE);
+ log_init(debug, LOG_DAEMON);
+ log_setverbose(ospfd_conf->opts & OSPFD_OPT_VERBOSE);
if (!debug)
daemon(1, 0);
@@ -363,7 +364,7 @@ main_dispatch_ospfe(int fd, short event, void *bula)
case IMSG_CTL_LOG_VERBOSE:
/* already checked by ospfe */
memcpy(&verbose, imsg.data, sizeof(verbose));
- log_verbose(verbose);
+ log_setverbose(verbose);
break;
default:
log_debug("main_dispatch_ospfe: error handling imsg %d",
diff --git a/usr.sbin/ospf6d/ospf6d.h b/usr.sbin/ospf6d/ospf6d.h
index abed9c97e2a..52514f09229 100644
--- a/usr.sbin/ospf6d/ospf6d.h
+++ b/usr.sbin/ospf6d/ospf6d.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ospf6d.h,v 1.33 2017/06/19 19:55:57 friehm Exp $ */
+/* $OpenBSD: ospf6d.h,v 1.34 2017/08/12 16:27:50 benno Exp $ */
/*
* Copyright (c) 2004, 2007 Esben Norby <norby@openbsd.org>
@@ -30,6 +30,7 @@
#include <imsg.h>
#include "ospf6.h"
+#include "log.h"
#define CONF_FILE "/etc/ospf6d.conf"
#define OSPF6D_SOCKET "/var/run/ospf6d.sock"
diff --git a/usr.sbin/ospf6d/ospfe.c b/usr.sbin/ospf6d/ospfe.c
index 91bf90be4c3..d53ffbbf723 100644
--- a/usr.sbin/ospf6d/ospfe.c
+++ b/usr.sbin/ospf6d/ospfe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ospfe.c,v 1.50 2016/12/22 22:56:52 jca Exp $ */
+/* $OpenBSD: ospfe.c,v 1.51 2017/08/12 16:27:50 benno Exp $ */
/*
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -119,8 +119,14 @@ ospfe(struct ospfd_conf *xconf, int pipe_parent2ospfe[2], int pipe_ospfe2rde[2],
fatal("chdir(\"/\")");
setproctitle("ospf engine");
+ /*
+ * XXX needed with fork+exec
+ * log_init(debug, LOG_DAEMON);
+ * log_setverbose(verbose);
+ */
+
ospfd_process = PROC_OSPF_ENGINE;
- log_procname = log_procnames[ospfd_process];
+ log_procinit(log_procnames[ospfd_process]);
if (setgroups(1, &pw->pw_gid) ||
setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
diff --git a/usr.sbin/ospf6d/rde.c b/usr.sbin/ospf6d/rde.c
index 62de3c33521..4aab79e705b 100644
--- a/usr.sbin/ospf6d/rde.c
+++ b/usr.sbin/ospf6d/rde.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde.c,v 1.71 2017/06/19 19:55:57 friehm Exp $ */
+/* $OpenBSD: rde.c,v 1.72 2017/08/12 16:27:50 benno Exp $ */
/*
* Copyright (c) 2004, 2005 Claudio Jeker <claudio@openbsd.org>
@@ -142,8 +142,14 @@ rde(struct ospfd_conf *xconf, int pipe_parent2rde[2], int pipe_ospfe2rde[2],
fatal("chdir(\"/\")");
setproctitle("route decision engine");
+ /*
+ * XXX needed with fork+exec
+ * log_init(debug, LOG_DAEMON);
+ * log_setverbose(verbose);
+ */
+
ospfd_process = PROC_RDE_ENGINE;
- log_procname = log_procnames[ospfd_process];
+ log_procinit(log_procnames[ospfd_process]);
if (setgroups(1, &pw->pw_gid) ||
setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
@@ -600,7 +606,7 @@ rde_dispatch_imsg(int fd, short event, void *bula)
case IMSG_CTL_LOG_VERBOSE:
/* already checked by ospfe */
memcpy(&verbose, imsg.data, sizeof(verbose));
- log_verbose(verbose);
+ log_setverbose(verbose);
break;
default:
log_debug("rde_dispatch_imsg: unexpected imsg %d",