Index | Thread | Search

From:
Rafael Sadowski <rafael@sizeofvoid.org>
Subject:
relayd: standardize logging with bgpd
To:
tech@openbsd.org
Date:
Sat, 28 Feb 2026 08:19:26 +0100

Download raw body.

Thread
  • Rafael Sadowski:

    relayd: standardize logging with bgpd

This diff extracts the logging prototypes into a "new" log.h. It's
a copy from bgpd so it also improves the logit fatal case.

OK?

diff --git a/usr.sbin/relayd/agentx_control.c b/usr.sbin/relayd/agentx_control.c
index b5f75f20ce6..2f1d756f348 100644
--- a/usr.sbin/relayd/agentx_control.c
+++ b/usr.sbin/relayd/agentx_control.c
@@ -38,6 +38,7 @@
 #include <imsg.h>
 
 #include "relayd.h"
+#include "log.h"
 
 #define RELAYD_MIB	"1.3.6.1.4.1.30155.3"
 #define SNMP_ELEMENT(x...)	do {				\
diff --git a/usr.sbin/relayd/ca.c b/usr.sbin/relayd/ca.c
index 167fb1cf756..8749f2cbeee 100644
--- a/usr.sbin/relayd/ca.c
+++ b/usr.sbin/relayd/ca.c
@@ -34,6 +34,7 @@
 #include <openssl/engine.h>
 
 #include "relayd.h"
+#include "log.h"
 
 void	 ca_init(struct privsep *, struct privsep_proc *p, void *);
 void	 ca_launch(void);
diff --git a/usr.sbin/relayd/carp.c b/usr.sbin/relayd/carp.c
index fad01387738..f37b3c6f823 100644
--- a/usr.sbin/relayd/carp.c
+++ b/usr.sbin/relayd/carp.c
@@ -29,6 +29,7 @@
 #include <unistd.h>
 
 #include "relayd.h"
+#include "log.h"
 
 struct carpgroup {
 	TAILQ_ENTRY(carpgroup)	 entry;
diff --git a/usr.sbin/relayd/check_icmp.c b/usr.sbin/relayd/check_icmp.c
index 3d251b28651..bd22334b78c 100644
--- a/usr.sbin/relayd/check_icmp.c
+++ b/usr.sbin/relayd/check_icmp.c
@@ -35,6 +35,7 @@
 #include <stdlib.h>
 
 #include "relayd.h"
+#include "log.h"
 
 void	icmp_setup(struct relayd *, struct ctl_icmp_event *, int);
 void	check_icmp_add(struct ctl_icmp_event *, int, struct timeval *,
diff --git a/usr.sbin/relayd/check_script.c b/usr.sbin/relayd/check_script.c
index d0cd1f6fc7f..01c69cb6cea 100644
--- a/usr.sbin/relayd/check_script.c
+++ b/usr.sbin/relayd/check_script.c
@@ -27,6 +27,7 @@
 #include <pwd.h>
 
 #include "relayd.h"
+#include "log.h"
 
 void	 script_sig_alarm(int);
 
diff --git a/usr.sbin/relayd/check_tcp.c b/usr.sbin/relayd/check_tcp.c
index 4f6ded93507..9f036fc7188 100644
--- a/usr.sbin/relayd/check_tcp.c
+++ b/usr.sbin/relayd/check_tcp.c
@@ -34,6 +34,7 @@
 #include <imsg.h>
 
 #include "relayd.h"
+#include "log.h"
 
 void	tcp_write(int, short, void *);
 void	tcp_host_up(struct ctl_tcp_event *);
diff --git a/usr.sbin/relayd/check_tls.c b/usr.sbin/relayd/check_tls.c
index 04df50308b0..e799e147bdd 100644
--- a/usr.sbin/relayd/check_tls.c
+++ b/usr.sbin/relayd/check_tls.c
@@ -29,6 +29,7 @@
 #include <imsg.h>
 
 #include "relayd.h"
+#include "log.h"
 
 void	check_tls_read(int, short, void *);
 void	check_tls_write(int, short, void *);
diff --git a/usr.sbin/relayd/config.c b/usr.sbin/relayd/config.c
index ec7ec873547..b346beff19d 100644
--- a/usr.sbin/relayd/config.c
+++ b/usr.sbin/relayd/config.c
@@ -29,6 +29,7 @@
 #include <imsg.h>
 
 #include "relayd.h"
+#include "log.h"
 
 int
 config_init(struct relayd *env)
diff --git a/usr.sbin/relayd/control.c b/usr.sbin/relayd/control.c
index bd13efd1d9b..ebba6939266 100644
--- a/usr.sbin/relayd/control.c
+++ b/usr.sbin/relayd/control.c
@@ -31,6 +31,7 @@
 #include <imsg.h>
 
 #include "relayd.h"
+#include "log.h"
 
 #define	CONTROL_BACKLOG	5
 
diff --git a/usr.sbin/relayd/hce.c b/usr.sbin/relayd/hce.c
index e4db3c96c91..f6bdb3516f8 100644
--- a/usr.sbin/relayd/hce.c
+++ b/usr.sbin/relayd/hce.c
@@ -28,6 +28,7 @@
 #include <imsg.h>
 
 #include "relayd.h"
+#include "log.h"
 
 void	 hce_init(struct privsep *, struct privsep_proc *p, void *);
 void	 hce_launch_checks(int, short, void *);
diff --git a/usr.sbin/relayd/log.c b/usr.sbin/relayd/log.c
index b5e4308dbf4..b62359f7295 100644
--- a/usr.sbin/relayd/log.c
+++ b/usr.sbin/relayd/log.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: log.c,v 1.35 2017/03/21 12:06:56 bluhm Exp $	*/
+/*	$OpenBSD: log.c,v 1.64 2017/03/21 12:06:55 bluhm Exp $	*/
 
 /*
  * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -24,30 +24,11 @@
 #include <errno.h>
 #include <time.h>
 
-static int	 debug;
-static int	 verbose;
-const char	*log_procname;
-
-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)));
+#include "log.h"
+
+static int		 debug;
+static int		 verbose;
+static const char	*log_procname;
 
 void
 log_init(int n_debug, int facility)
@@ -168,7 +149,7 @@ log_debug(const char *emsg, ...)
 {
 	va_list	 ap;
 
-	if (verbose > 1) {
+	if (verbose) {
 		va_start(ap, emsg);
 		vlog(LOG_DEBUG, emsg, ap);
 		va_end(ap);
@@ -189,10 +170,10 @@ vfatalc(int code, const char *emsg, va_list ap)
 		sep = "";
 	}
 	if (code)
-		logit(LOG_CRIT, "%s: %s%s%s",
+		logit(LOG_CRIT, "fatal in %s: %s%s%s",
 		    log_procname, s, sep, strerror(code));
 	else
-		logit(LOG_CRIT, "%s%s%s", log_procname, sep, s);
+		logit(LOG_CRIT, "fatal in %s%s%s", log_procname, sep, s);
 }
 
 void
diff --git a/usr.sbin/relayd/log.h b/usr.sbin/relayd/log.h
new file mode 100644
index 00000000000..e91c2392877
--- /dev/null
+++ b/usr.sbin/relayd/log.h
@@ -0,0 +1,46 @@
+/*	$OpenBSD: log.h,v 1.20 2020/10/21 06:48:33 claudio 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.
+ */
+
+#ifndef LOG_H
+#define LOG_H
+
+#include <sys/types.h>
+#include <stdarg.h>
+
+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/relayd/parse.y b/usr.sbin/relayd/parse.y
index b4660f7f1ef..ab8f6196ad0 100644
--- a/usr.sbin/relayd/parse.y
+++ b/usr.sbin/relayd/parse.y
@@ -57,6 +57,7 @@
 
 #include "relayd.h"
 #include "http.h"
+#include "log.h"
 
 TAILQ_HEAD(files, file)		 files = TAILQ_HEAD_INITIALIZER(files);
 static struct file {
diff --git a/usr.sbin/relayd/pfe.c b/usr.sbin/relayd/pfe.c
index 3aba811eed5..d516145ef87 100644
--- a/usr.sbin/relayd/pfe.c
+++ b/usr.sbin/relayd/pfe.c
@@ -33,6 +33,7 @@
 #include <imsg.h>
 
 #include "relayd.h"
+#include "log.h"
 
 void	 pfe_init(struct privsep *, struct privsep_proc *p, void *);
 void	 pfe_shutdown(void);
diff --git a/usr.sbin/relayd/pfe_filter.c b/usr.sbin/relayd/pfe_filter.c
index c1851260c62..464f63c0d87 100644
--- a/usr.sbin/relayd/pfe_filter.c
+++ b/usr.sbin/relayd/pfe_filter.c
@@ -38,6 +38,7 @@
 #define MINIMUM(a, b)	(((a) < (b)) ? (a) : (b))
 
 #include "relayd.h"
+#include "log.h"
 
 int	 transaction_init(struct relayd *, const char *);
 int	 transaction_commit(struct relayd *);
diff --git a/usr.sbin/relayd/pfe_route.c b/usr.sbin/relayd/pfe_route.c
index 4850aef9b05..53eeb4eac30 100644
--- a/usr.sbin/relayd/pfe_route.c
+++ b/usr.sbin/relayd/pfe_route.c
@@ -33,6 +33,7 @@
 #include <errno.h>
 
 #include "relayd.h"
+#include "log.h"
 
 void
 init_routes(struct relayd *env)
diff --git a/usr.sbin/relayd/proc.c b/usr.sbin/relayd/proc.c
index 3eb00aa0381..b884e5ceed1 100644
--- a/usr.sbin/relayd/proc.c
+++ b/usr.sbin/relayd/proc.c
@@ -35,6 +35,7 @@
 #include <imsg.h>
 
 #include "relayd.h"
+#include "log.h"
 
 void	 proc_exec(struct privsep *, struct privsep_proc *, unsigned int, int,
 	    char **);
diff --git a/usr.sbin/relayd/relay.c b/usr.sbin/relayd/relay.c
index ff2a6796502..77e2d3c031c 100644
--- a/usr.sbin/relayd/relay.c
+++ b/usr.sbin/relayd/relay.c
@@ -42,6 +42,7 @@
 #include <tls.h>
 
 #include "relayd.h"
+#include "log.h"
 
 #define MINIMUM(a, b)	(((a) < (b)) ? (a) : (b))
 
diff --git a/usr.sbin/relayd/relay_http.c b/usr.sbin/relayd/relay_http.c
index e9b9c4449e5..70b0de1ac86 100644
--- a/usr.sbin/relayd/relay_http.c
+++ b/usr.sbin/relayd/relay_http.c
@@ -39,6 +39,7 @@
 
 #include "relayd.h"
 #include "http.h"
+#include "log.h"
 
 static int	_relay_lookup_url(struct ctl_relay_event *, char *, char *,
 		    char *, struct kv *);
diff --git a/usr.sbin/relayd/relay_udp.c b/usr.sbin/relayd/relay_udp.c
index 1a4751d0d73..07f0173f4ad 100644
--- a/usr.sbin/relayd/relay_udp.c
+++ b/usr.sbin/relayd/relay_udp.c
@@ -36,6 +36,7 @@
 #include <imsg.h>
 
 #include "relayd.h"
+#include "log.h"
 
 extern volatile sig_atomic_t relay_sessions;
 extern objid_t relay_conid;
diff --git a/usr.sbin/relayd/relayd.c b/usr.sbin/relayd/relayd.c
index 612dda56920..4c9337d0570 100644
--- a/usr.sbin/relayd/relayd.c
+++ b/usr.sbin/relayd/relayd.c
@@ -48,6 +48,7 @@
 #include <tls.h>
 
 #include "relayd.h"
+#include "log.h"
 
 #define MAXIMUM(a, b)	(((a) > (b)) ? (a) : (b))
 
diff --git a/usr.sbin/relayd/relayd.h b/usr.sbin/relayd/relayd.h
index 0832e799f10..a43540d1533 100644
--- a/usr.sbin/relayd/relayd.h
+++ b/usr.sbin/relayd/relayd.h
@@ -1399,28 +1399,6 @@ void	 snmp_hosttrap(struct relayd *, struct table *, struct host *);
 void		shuffle_init(struct shuffle *);
 u_int16_t	shuffle_generate16(struct shuffle *);
 
-/* log.c */
-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)));
-
 /* proc.c */
 enum privsep_procid
 	    proc_getid(struct privsep_proc *, unsigned int, const char *);
diff --git a/usr.sbin/relayd/ssl.c b/usr.sbin/relayd/ssl.c
index 31eebee64e4..ca1f7171a7d 100644
--- a/usr.sbin/relayd/ssl.c
+++ b/usr.sbin/relayd/ssl.c
@@ -29,6 +29,7 @@
 #include <openssl/err.h>
 
 #include "relayd.h"
+#include "log.h"
 
 int	ssl_password_cb(char *, int, int, void *);
 
diff --git a/usr.sbin/relayd/util.c b/usr.sbin/relayd/util.c
index 751e82c43c8..96289aaa98d 100644
--- a/usr.sbin/relayd/util.c
+++ b/usr.sbin/relayd/util.c
@@ -27,6 +27,7 @@
 #include <ctype.h>
 
 #include "relayd.h"
+#include "log.h"
 
 const char *
 host_error(enum host_error he)