diff options
author | benno <benno@openbsd.org> | 2016-09-02 16:20:34 +0000 |
---|---|---|
committer | benno <benno@openbsd.org> | 2016-09-02 16:20:34 +0000 |
commit | 2e743b2f0192c2576239420397f9d02d1f0c5ca6 (patch) | |
tree | a09d6a05795a5179f1322e549ca3742a36319402 /usr.sbin/dvmrpd | |
parent | Move snmp options into struct relayd_config and delay start of the (diff) | |
download | wireguard-openbsd-2e743b2f0192c2576239420397f9d02d1f0c5ca6.tar.xz wireguard-openbsd-2e743b2f0192c2576239420397f9d02d1f0c5ca6.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@
Diffstat (limited to 'usr.sbin/dvmrpd')
-rw-r--r-- | usr.sbin/dvmrpd/Makefile | 4 | ||||
-rw-r--r-- | usr.sbin/dvmrpd/dvmrpd.c | 3 | ||||
-rw-r--r-- | usr.sbin/dvmrpd/dvmrpd.h | 8 | ||||
-rw-r--r-- | usr.sbin/dvmrpd/dvmrpe.c | 3 | ||||
-rw-r--r-- | usr.sbin/dvmrpd/log.c | 83 | ||||
-rw-r--r-- | usr.sbin/dvmrpd/log.h | 11 | ||||
-rw-r--r-- | usr.sbin/dvmrpd/logmsg.c | 90 | ||||
-rw-r--r-- | usr.sbin/dvmrpd/rde.c | 3 |
8 files changed, 121 insertions, 84 deletions
diff --git a/usr.sbin/dvmrpd/Makefile b/usr.sbin/dvmrpd/Makefile index badf87aaf5a..bbcd65024ed 100644 --- a/usr.sbin/dvmrpd/Makefile +++ b/usr.sbin/dvmrpd/Makefile @@ -1,8 +1,8 @@ -# $OpenBSD: Makefile,v 1.4 2010/05/26 16:44:32 nicm Exp $ +# $OpenBSD: Makefile,v 1.5 2016/09/02 16:20:34 benno Exp $ PROG= dvmrpd SRCS= ask_nbrs2.c control.c dvmrpd.c dvmrpe.c graft.c graft_ack.c \ - group.c igmp.c interface.c in_cksum.c kmroute.c kroute.c log.c \ + group.c igmp.c interface.c in_cksum.c kmroute.c kroute.c log.c logmsg.c \ nbrs2.c neighbor.c packet.c parse.y printconf.c probe.c prune.c rde.c \ rde_mfc.c rde_srt.c report.c diff --git a/usr.sbin/dvmrpd/dvmrpd.c b/usr.sbin/dvmrpd/dvmrpd.c index cd39c5f8e38..bcb526717ba 100644 --- a/usr.sbin/dvmrpd/dvmrpd.c +++ b/usr.sbin/dvmrpd/dvmrpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dvmrpd.c,v 1.24 2016/09/02 15:38:08 renato Exp $ */ +/* $OpenBSD: dvmrpd.c,v 1.25 2016/09/02 16:20:34 benno Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -109,6 +109,7 @@ main(int argc, char *argv[]) conffile = CONF_FILE; dvmrpd_process = PROC_MAIN; + log_procname = log_procnames[dvmrpd_process]; log_init(1); /* log to stderr until daemonized */ log_verbose(1); diff --git a/usr.sbin/dvmrpd/dvmrpd.h b/usr.sbin/dvmrpd/dvmrpd.h index 3bfc4f39be9..a8cf93ff399 100644 --- a/usr.sbin/dvmrpd/dvmrpd.h +++ b/usr.sbin/dvmrpd/dvmrpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dvmrpd.h,v 1.21 2015/09/27 17:29:45 stsp Exp $ */ +/* $OpenBSD: dvmrpd.h,v 1.22 2016/09/02 16:20:34 benno Exp $ */ /* * Copyright (c) 2004, 2005, 2006 Esben Norby <norby@openbsd.org> @@ -52,6 +52,12 @@ #define MAXVIFS 32 /* XXX */ +static const char * const log_procnames[] = { + "parent", + "dvmrpe", + "rde" +}; + struct imsgev { struct imsgbuf ibuf; void (*handler)(int, short, void *); diff --git a/usr.sbin/dvmrpd/dvmrpe.c b/usr.sbin/dvmrpd/dvmrpe.c index f907b122fc2..76e232b833e 100644 --- a/usr.sbin/dvmrpd/dvmrpe.c +++ b/usr.sbin/dvmrpd/dvmrpe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dvmrpe.c,v 1.18 2016/09/02 15:38:08 renato Exp $ */ +/* $OpenBSD: dvmrpe.c,v 1.19 2016/09/02 16:20:34 benno Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -119,6 +119,7 @@ dvmrpe(struct dvmrpd_conf *xconf, int pipe_parent2dvmrpe[2], setproctitle("dvmrp engine"); dvmrpd_process = PROC_DVMRP_ENGINE; + log_procname = log_procnames[dvmrpd_process]; if (setgroups(1, &pw->pw_gid) || setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) || diff --git a/usr.sbin/dvmrpd/log.c b/usr.sbin/dvmrpd/log.c index daabb5f6053..60190075e1b 100644 --- a/usr.sbin/dvmrpd/log.c +++ b/usr.sbin/dvmrpd/log.c @@ -1,4 +1,4 @@ -/* $OpenBSD: log.c,v 1.4 2014/11/03 16:55:59 bluhm Exp $ */ +/* $OpenBSD: log.c,v 1.5 2016/09/02 16:20:34 benno Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -22,20 +22,16 @@ #include <stdlib.h> #include <string.h> #include <syslog.h> +#include <time.h> #include <unistd.h> +#include "log.h" #include "igmp.h" #include "dvmrpd.h" -#include "log.h" - -static const char * const procnames[] = { - "parent", - "dvmrpe", - "rde" -}; -int debug; -int verbose; +int debug; +int verbose; +const char *log_procname; void log_init(int n_debug) @@ -145,15 +141,15 @@ void fatal(const char *emsg) { if (emsg == NULL) - logit(LOG_CRIT, "fatal in %s: %s", procnames[dvmrpd_process], + logit(LOG_CRIT, "fatal in %s: %s", log_procname, strerror(errno)); else if (errno) logit(LOG_CRIT, "fatal in %s: %s: %s", - procnames[dvmrpd_process], emsg, strerror(errno)); + log_procname, emsg, strerror(errno)); else logit(LOG_CRIT, "fatal in %s: %s", - procnames[dvmrpd_process], emsg); + log_procname, emsg); if (dvmrpd_process == PROC_MAIN) exit(1); @@ -167,64 +163,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_1_WAY: - return ("1-WAY"); - case NBR_STA_2_WAY: - return ("2-WAY"); - default: - return ("UNKNOWN"); - } -} - -const char * -if_state_name(int state) -{ - switch (state) { - case IF_STA_DOWN: - return ("DOWN"); - case IF_STA_QUERIER: - return ("QUERIER"); - case IF_STA_NONQUERIER: - return ("NONQUERIER"); - default: - return ("UNKNOWN"); - } -} - -const char * -group_state_name(int state) -{ - switch (state) { - case GRP_STA_NO_MEMB_PRSNT: - return ("NO MEMBER"); - case GRP_STA_MEMB_PRSNT: - return ("MEMBER"); - case GRP_STA_V1_MEMB_PRSNT: - return ("V1 MEMBER"); - case GRP_STA_CHECK_MEMB: - return ("CHECKING"); - default: - return ("UNKNOWN"); - } -} - -const char * -if_type_name(enum iface_type type) -{ - switch (type) { - case IF_TYPE_POINTOPOINT: - return ("POINTOPOINT"); - case IF_TYPE_BROADCAST: - return ("BROADCAST"); - } - /* NOTREACHED */ - return ("UNKNOWN"); -} diff --git a/usr.sbin/dvmrpd/log.h b/usr.sbin/dvmrpd/log.h index 100dcc3bae6..fcf54d924e1 100644 --- a/usr.sbin/dvmrpd/log.h +++ b/usr.sbin/dvmrpd/log.h @@ -1,4 +1,4 @@ -/* $OpenBSD: log.h,v 1.3 2014/11/03 16:55:59 bluhm Exp $ */ +/* $OpenBSD: log.h,v 1.4 2016/09/02 16:20:34 benno Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -16,10 +16,13 @@ * 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> + +extern const char *log_procname; void log_init(int); void log_verbose(int); @@ -32,4 +35,4 @@ void log_debug(const char *, ...); void fatal(const char *) __dead; void fatalx(const char *) __dead; -#endif /* _LOG_H_ */ +#endif /* LOG_H */ diff --git a/usr.sbin/dvmrpd/logmsg.c b/usr.sbin/dvmrpd/logmsg.c new file mode 100644 index 00000000000..09847f4a93c --- /dev/null +++ b/usr.sbin/dvmrpd/logmsg.c @@ -0,0 +1,90 @@ +/* $OpenBSD: logmsg.c,v 1.1 2016/09/02 16:20:34 benno Exp $ */ + +/* + * 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 + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <errno.h> +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <syslog.h> +#include <unistd.h> + +#include "igmp.h" +#include "dvmrpd.h" +#include "log.h" + +/* names */ +const char * +nbr_state_name(int state) +{ + switch (state) { + case NBR_STA_DOWN: + return ("DOWN"); + case NBR_STA_1_WAY: + return ("1-WAY"); + case NBR_STA_2_WAY: + return ("2-WAY"); + default: + return ("UNKNOWN"); + } +} + +const char * +if_state_name(int state) +{ + switch (state) { + case IF_STA_DOWN: + return ("DOWN"); + case IF_STA_QUERIER: + return ("QUERIER"); + case IF_STA_NONQUERIER: + return ("NONQUERIER"); + default: + return ("UNKNOWN"); + } +} + +const char * +group_state_name(int state) +{ + switch (state) { + case GRP_STA_NO_MEMB_PRSNT: + return ("NO MEMBER"); + case GRP_STA_MEMB_PRSNT: + return ("MEMBER"); + case GRP_STA_V1_MEMB_PRSNT: + return ("V1 MEMBER"); + case GRP_STA_CHECK_MEMB: + return ("CHECKING"); + default: + return ("UNKNOWN"); + } +} + +const char * +if_type_name(enum iface_type type) +{ + switch (type) { + case IF_TYPE_POINTOPOINT: + return ("POINTOPOINT"); + case IF_TYPE_BROADCAST: + return ("BROADCAST"); + } + /* NOTREACHED */ + return ("UNKNOWN"); +} diff --git a/usr.sbin/dvmrpd/rde.c b/usr.sbin/dvmrpd/rde.c index 99149157ecf..fa7ef1d8a70 100644 --- a/usr.sbin/dvmrpd/rde.c +++ b/usr.sbin/dvmrpd/rde.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.c,v 1.28 2016/09/02 15:38:08 renato Exp $ */ +/* $OpenBSD: rde.c,v 1.29 2016/09/02 16:20:34 benno Exp $ */ /* * Copyright (c) 2004, 2005 Claudio Jeker <claudio@openbsd.org> @@ -98,6 +98,7 @@ rde(struct dvmrpd_conf *xconf, int pipe_parent2rde[2], int pipe_dvmrpe2rde[2], setproctitle("route decision engine"); dvmrpd_process = PROC_RDE_ENGINE; + log_procname = log_procnames[dvmrpd_process]; if (setgroups(1, &pw->pw_gid) || setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) || |