Download raw body.
httpd: standardize logging with bgpd
On Sat, Feb 28, 2026 at 08:10:59AM +0100, Rafael Sadowski wrote:
> 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?
If you want this then you should also remove the prototypes in httpd.h
With that done OK claudio@ (same for relayd).
I dislike a few things about log.c especially the fact that it needs extra
memory to log information. I tried to fix this in bgpd but am not happy
with my current diff.
> diff --git a/usr.sbin/httpd/config.c b/usr.sbin/httpd/config.c
> index 300a5f2caca..6f93e1187a4 100644
> --- a/usr.sbin/httpd/config.c
> +++ b/usr.sbin/httpd/config.c
> @@ -31,6 +31,7 @@
> #include <imsg.h>
>
> #include "httpd.h"
> +#include "log.h"
>
> int config_getserver_config(struct httpd *, struct server *,
> struct imsg *);
> diff --git a/usr.sbin/httpd/control.c b/usr.sbin/httpd/control.c
> index 9a4eb3b5163..5483a4a3f8b 100644
> --- a/usr.sbin/httpd/control.c
> +++ b/usr.sbin/httpd/control.c
> @@ -31,6 +31,7 @@
> #include <imsg.h>
>
> #include "httpd.h"
> +#include "log.h"
>
> #define CONTROL_BACKLOG 5
>
> diff --git a/usr.sbin/httpd/httpd.c b/usr.sbin/httpd/httpd.c
> index c2d74de03fe..a092a16cd82 100644
> --- a/usr.sbin/httpd/httpd.c
> +++ b/usr.sbin/httpd/httpd.c
> @@ -42,6 +42,7 @@
> #include <pwd.h>
>
> #include "httpd.h"
> +#include "log.h"
>
> #define MAXIMUM(a, b) (((a) > (b)) ? (a) : (b))
>
> diff --git a/usr.sbin/httpd/log.c b/usr.sbin/httpd/log.c
> index b7e25a64720..b62359f7295 100644
> --- a/usr.sbin/httpd/log.c
> +++ b/usr.sbin/httpd/log.c
> @@ -1,4 +1,4 @@
> -/* $OpenBSD: log.c,v 1.14 2017/03/21 12:06:55 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/httpd/log.h b/usr.sbin/httpd/log.h
> new file mode 100644
> index 00000000000..e91c2392877
> --- /dev/null
> +++ b/usr.sbin/httpd/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/httpd/logger.c b/usr.sbin/httpd/logger.c
> index 31f441011ab..434a93f20ae 100644
> --- a/usr.sbin/httpd/logger.c
> +++ b/usr.sbin/httpd/logger.c
> @@ -29,6 +29,7 @@
> #include <imsg.h>
>
> #include "httpd.h"
> +#include "log.h"
>
> int logger_dispatch_parent(int, struct privsep_proc *,
> struct imsg *);
> diff --git a/usr.sbin/httpd/proc.c b/usr.sbin/httpd/proc.c
> index 66d528668df..9d2773c0e00 100644
> --- a/usr.sbin/httpd/proc.c
> +++ b/usr.sbin/httpd/proc.c
> @@ -35,6 +35,7 @@
> #include <imsg.h>
>
> #include "httpd.h"
> +#include "log.h"
>
> void proc_exec(struct privsep *, struct privsep_proc *, unsigned int, int,
> char **);
> diff --git a/usr.sbin/httpd/server.c b/usr.sbin/httpd/server.c
> index a38cf018d81..82b1376bfac 100644
> --- a/usr.sbin/httpd/server.c
> +++ b/usr.sbin/httpd/server.c
> @@ -43,6 +43,7 @@
> #include <vis.h>
>
> #include "httpd.h"
> +#include "log.h"
>
> #define MINIMUM(a, b) (((a) < (b)) ? (a) : (b))
>
> diff --git a/usr.sbin/httpd/server_fcgi.c b/usr.sbin/httpd/server_fcgi.c
> index c5f9917204c..f8d21df8397 100644
> --- a/usr.sbin/httpd/server_fcgi.c
> +++ b/usr.sbin/httpd/server_fcgi.c
> @@ -36,6 +36,7 @@
>
> #include "httpd.h"
> #include "http.h"
> +#include "log.h"
>
> #define FCGI_PADDING_SIZE 255
> #define FCGI_RECORD_SIZE \
> diff --git a/usr.sbin/httpd/server_http.c b/usr.sbin/httpd/server_http.c
> index 6e5fce04845..b972f90e112 100644
> --- a/usr.sbin/httpd/server_http.c
> +++ b/usr.sbin/httpd/server_http.c
> @@ -42,6 +42,7 @@
>
> #include "httpd.h"
> #include "http.h"
> +#include "log.h"
> #include "patterns.h"
>
> static int server_httpmethod_cmp(const void *, const void *);
>
--
:wq Claudio
httpd: standardize logging with bgpd