summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbenno <benno@openbsd.org>2016-09-02 14:02:48 +0000
committerbenno <benno@openbsd.org>2016-09-02 14:02:48 +0000
commit2d29f8f3ff8abb5086a5ba81fc389531f35640a1 (patch)
tree3ee491705d1082a3a610278b890db4e496a8bbf2
parentwork on making log.c similar in all daemons: (diff)
downloadwireguard-openbsd-2d29f8f3ff8abb5086a5ba81fc389531f35640a1.tar.xz
wireguard-openbsd-2d29f8f3ff8abb5086a5ba81fc389531f35640a1.zip
work on making log.c similar in all daemons:
move daemon-local functions into new logmsg.c, and reduce the (mostly whitespace) differences so that log.c's can be diffed easily. ok claudio@, feedback from henning@, deraadt@, reyk@
-rw-r--r--usr.sbin/ospfctl/Makefile4
-rw-r--r--usr.sbin/ospfd/Makefile4
-rw-r--r--usr.sbin/ospfd/log.c138
-rw-r--r--usr.sbin/ospfd/log.h31
-rw-r--r--usr.sbin/ospfd/ospfd.c3
-rw-r--r--usr.sbin/ospfd/ospfd.h8
-rw-r--r--usr.sbin/ospfd/ospfe.c3
-rw-r--r--usr.sbin/ospfd/rde.c3
8 files changed, 43 insertions, 151 deletions
diff --git a/usr.sbin/ospfctl/Makefile b/usr.sbin/ospfctl/Makefile
index f713544c012..cfd5e4ccb71 100644
--- a/usr.sbin/ospfctl/Makefile
+++ b/usr.sbin/ospfctl/Makefile
@@ -1,9 +1,9 @@
-# $OpenBSD: Makefile,v 1.4 2010/05/26 16:44:32 nicm Exp $
+# $OpenBSD: Makefile,v 1.5 2016/09/02 14:02:48 benno Exp $
.PATH: ${.CURDIR}/../ospfd
PROG= ospfctl
-SRCS= log.c ospfctl.c parser.c
+SRCS= logmsg.c ospfctl.c parser.c
CFLAGS+= -Wall
CFLAGS+= -Wstrict-prototypes -Wmissing-prototypes
CFLAGS+= -Wshadow -Wpointer-arith -Wcast-qual
diff --git a/usr.sbin/ospfd/Makefile b/usr.sbin/ospfd/Makefile
index 1837268eeb3..9094371611e 100644
--- a/usr.sbin/ospfd/Makefile
+++ b/usr.sbin/ospfd/Makefile
@@ -1,9 +1,9 @@
-# $OpenBSD: Makefile,v 1.8 2010/05/26 16:44:32 nicm Exp $
+# $OpenBSD: Makefile,v 1.9 2016/09/02 14:02:48 benno Exp $
PROG= ospfd
SRCS= area.c auth.c carp.c control.c database.c hello.c \
in_cksum.c interface.c iso_cksum.c kroute.c lsack.c \
- lsreq.c lsupdate.c log.c neighbor.c ospfd.c ospfe.c packet.c \
+ lsreq.c lsupdate.c log.c logmsg.c neighbor.c ospfd.c ospfe.c packet.c \
parse.y printconf.c rde.c rde_lsdb.c rde_spf.c name2id.c
MAN= ospfd.8 ospfd.conf.5
diff --git a/usr.sbin/ospfd/log.c b/usr.sbin/ospfd/log.c
index 8fe81b24af1..48d344ffb43 100644
--- a/usr.sbin/ospfd/log.c
+++ b/usr.sbin/ospfd/log.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.c,v 1.8 2014/11/03 07:40:31 bluhm Exp $ */
+/* $OpenBSD: log.c,v 1.9 2016/09/02 14:02:48 benno Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -22,19 +22,15 @@
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
+#include <time.h>
#include <unistd.h>
-#include "ospfd.h"
#include "log.h"
+#include "ospfd.h"
-static const char * const procnames[] = {
- "parent",
- "ospfe",
- "rde"
-};
-
-int debug;
-int verbose;
+int debug;
+int verbose;
+const char *log_procname;
void
log_init(int n_debug)
@@ -144,15 +140,15 @@ void
fatal(const char *emsg)
{
if (emsg == NULL)
- logit(LOG_CRIT, "fatal in %s: %s", procnames[ospfd_process],
+ logit(LOG_CRIT, "fatal in %s: %s", log_procname,
strerror(errno));
else
if (errno)
logit(LOG_CRIT, "fatal in %s: %s: %s",
- procnames[ospfd_process], emsg, strerror(errno));
+ log_procname, emsg, strerror(errno));
else
logit(LOG_CRIT, "fatal in %s: %s",
- procnames[ospfd_process], emsg);
+ log_procname, emsg);
if (ospfd_process == PROC_MAIN)
exit(1);
@@ -166,119 +162,3 @@ fatalx(const char *emsg)
errno = 0;
fatal(emsg);
}
-
-/* names */
-const char *
-nbr_state_name(int state)
-{
- switch (state) {
- case NBR_STA_DOWN:
- return ("DOWN");
- case NBR_STA_ATTEMPT:
- return ("ATTMP");
- case NBR_STA_INIT:
- return ("INIT");
- case NBR_STA_2_WAY:
- return ("2-WAY");
- case NBR_STA_XSTRT:
- return ("EXSTA");
- case NBR_STA_SNAP:
- return ("SNAP");
- case NBR_STA_XCHNG:
- return ("EXCHG");
- case NBR_STA_LOAD:
- return ("LOAD");
- case NBR_STA_FULL:
- return ("FULL");
- default:
- return ("UNKNW");
- }
-}
-
-const char *
-if_state_name(int state)
-{
- switch (state) {
- case IF_STA_DOWN:
- return ("DOWN");
- case IF_STA_LOOPBACK:
- return ("LOOP");
- case IF_STA_WAITING:
- return ("WAIT");
- case IF_STA_POINTTOPOINT:
- return ("P2P");
- case IF_STA_DROTHER:
- return ("OTHER");
- case IF_STA_BACKUP:
- return ("BCKUP");
- case IF_STA_DR:
- return ("DR");
- default:
- return ("UNKNW");
- }
-}
-
-const char *
-if_type_name(enum iface_type type)
-{
- switch (type) {
- case IF_TYPE_POINTOPOINT:
- return ("POINTOPOINT");
- case IF_TYPE_BROADCAST:
- return ("BROADCAST");
- case IF_TYPE_NBMA:
- return ("NBMA");
- case IF_TYPE_POINTOMULTIPOINT:
- return ("POINTOMULTIPOINT");
- case IF_TYPE_VIRTUALLINK:
- return ("VIRTUALLINK");
- }
- /* NOTREACHED */
- return ("UNKNOWN");
-}
-
-const char *
-if_auth_name(enum auth_type type)
-{
- switch (type) {
- case AUTH_NONE:
- return ("none");
- case AUTH_SIMPLE:
- return ("simple");
- case AUTH_CRYPT:
- return ("crypt");
- }
- /* NOTREACHED */
- return ("unknown");
-}
-
-const char *
-dst_type_name(enum dst_type type)
-{
- switch (type) {
- case DT_NET:
- return ("Network");
- case DT_RTR:
- return ("Router");
- }
- /* NOTREACHED */
- return ("unknown");
-}
-
-const char *
-path_type_name(enum path_type type)
-{
- switch (type) {
- case PT_INTRA_AREA:
- return ("Intra-Area");
- case PT_INTER_AREA:
- return ("Inter-Area");
- case PT_TYPE1_EXT:
- return ("Type 1 ext");
- case PT_TYPE2_EXT:
- return ("Type 2 ext");
- }
- /* NOTREACHED */
- return ("unknown");
-}
-
diff --git a/usr.sbin/ospfd/log.h b/usr.sbin/ospfd/log.h
index 656afd86a87..166a5c7ea9e 100644
--- a/usr.sbin/ospfd/log.h
+++ b/usr.sbin/ospfd/log.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.h,v 1.7 2016/06/06 15:56:22 benno Exp $ */
+/* $OpenBSD: log.h,v 1.8 2016/09/02 14:02:48 benno Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -16,28 +16,31 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#ifndef _LOG_H_
-#define _LOG_H_
+#ifndef LOG_H
+#define LOG_H
#include <stdarg.h>
+#include <sys/cdefs.h>
-void log_init(int);
-void log_verbose(int);
-void logit(int, const char *, ...)
+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)
+void vlog(int, const char *, va_list)
__attribute__((__format__ (printf, 2, 0)));
-void log_warn(const char *, ...)
+void log_warn(const char *, ...)
__attribute__((__format__ (printf, 1, 2)));
-void log_warnx(const char *, ...)
+void log_warnx(const char *, ...)
__attribute__((__format__ (printf, 1, 2)));
-void log_info(const char *, ...)
+void log_info(const char *, ...)
__attribute__((__format__ (printf, 1, 2)));
-void log_debug(const char *, ...)
+void log_debug(const char *, ...)
__attribute__((__format__ (printf, 1, 2)));
-void fatal(const char *) __dead
+void fatal(const char *) __dead
__attribute__((__format__ (printf, 1, 0)));
-void fatalx(const char *) __dead
+void fatalx(const char *) __dead
__attribute__((__format__ (printf, 1, 0)));
-#endif /* _LOG_H_ */
+#endif /* LOG_H */
diff --git a/usr.sbin/ospfd/ospfd.c b/usr.sbin/ospfd/ospfd.c
index 932efb726bd..911a6db75df 100644
--- a/usr.sbin/ospfd/ospfd.c
+++ b/usr.sbin/ospfd/ospfd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ospfd.c,v 1.89 2016/02/02 17:51:11 sthen Exp $ */
+/* $OpenBSD: ospfd.c,v 1.90 2016/09/02 14:02:48 benno Exp $ */
/*
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -135,6 +135,7 @@ main(int argc, char *argv[])
conffile = CONF_FILE;
ospfd_process = PROC_MAIN;
+ log_procname = log_procnames[ospfd_process];
sockname = OSPFD_SOCKET;
log_init(1); /* log to stderr until daemonized */
diff --git a/usr.sbin/ospfd/ospfd.h b/usr.sbin/ospfd/ospfd.h
index 6569bb50238..d0abe6c6fbe 100644
--- a/usr.sbin/ospfd/ospfd.h
+++ b/usr.sbin/ospfd/ospfd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ospfd.h,v 1.94 2015/12/05 12:20:13 claudio Exp $ */
+/* $OpenBSD: ospfd.h,v 1.95 2016/09/02 14:02:48 benno Exp $ */
/*
* Copyright (c) 2004 Esben Norby <norby@openbsd.org>
@@ -61,6 +61,12 @@
#define F_REDISTRIBUTED 0x0100
#define F_FORCED_NEXTHOP 0x0200
+static const char * const log_procnames[] = {
+ "parent",
+ "ospfe",
+ "rde"
+};
+
struct imsgev {
struct imsgbuf ibuf;
void (*handler)(int, short, void *);
diff --git a/usr.sbin/ospfd/ospfe.c b/usr.sbin/ospfd/ospfe.c
index 5349fb06333..5efef533aa1 100644
--- a/usr.sbin/ospfd/ospfe.c
+++ b/usr.sbin/ospfd/ospfe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ospfe.c,v 1.94 2015/12/05 12:20:13 claudio Exp $ */
+/* $OpenBSD: ospfe.c,v 1.95 2016/09/02 14:02:48 benno Exp $ */
/*
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -123,6 +123,7 @@ ospfe(struct ospfd_conf *xconf, int pipe_parent2ospfe[2], int pipe_ospfe2rde[2],
setproctitle("ospf engine");
ospfd_process = PROC_OSPF_ENGINE;
+ log_procname = 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/ospfd/rde.c b/usr.sbin/ospfd/rde.c
index 3d2c9ae7fea..55f5311fba6 100644
--- a/usr.sbin/ospfd/rde.c
+++ b/usr.sbin/ospfd/rde.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde.c,v 1.101 2016/06/06 15:56:22 benno Exp $ */
+/* $OpenBSD: rde.c,v 1.102 2016/09/02 14:02:48 benno Exp $ */
/*
* Copyright (c) 2004, 2005 Claudio Jeker <claudio@openbsd.org>
@@ -126,6 +126,7 @@ rde(struct ospfd_conf *xconf, int pipe_parent2rde[2], int pipe_ospfe2rde[2],
setproctitle("route decision engine");
ospfd_process = PROC_RDE_ENGINE;
+ log_procname = log_procnames[ospfd_process];
if (setgroups(1, &pw->pw_gid) ||
setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||