From 95a737ed1bf7f89cb8e5367ef8e8e66a800084d7 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Thu, 25 Jan 2024 22:54:54 +0100 Subject: ldpd: use zlog recirculation for subprocesses This way, full functionality of `zlog_*` is available. Having `fatal()` be wrappers around `assertf()` also means we get backtraces, which is not the case for a plain `exit(1)`. Signed-off-by: David Lamparter --- ldpd/log.h | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) (limited to 'ldpd/log.h') diff --git a/ldpd/log.h b/ldpd/log.h index 641ad8ac5..aa6f70060 100644 --- a/ldpd/log.h +++ b/ldpd/log.h @@ -8,29 +8,30 @@ #ifndef LOG_H #define LOG_H -#include +#include "log.h" +#include "assert.h" extern const char *log_procname; -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_notice(const char *, ...) - __attribute__((__format__ (printf, 1, 2))); -void log_debug(const char *, ...) - __attribute__((__format__ (printf, 1, 2))); -void fatal(const char *) - __attribute__ ((noreturn)) - __attribute__((__format__ (printf, 1, 0))); -void fatalx(const char *) - __attribute__ ((noreturn)) - __attribute__((__format__ (printf, 1, 0))); +#define log_warnx zlog_err /* yes this is poorly named */ +#define log_warn zlog_warn +#define log_info zlog_info +#define log_notice zlog_notice /* not used anywhere */ +#define log_debug zlog_debug + +#define fatal(msg) \ + do { \ + assertf(0, "fatal in %s: %pSQq (%m)", log_procname, \ + (const char *)msg); \ + __builtin_unreachable(); \ + } while (0) \ + /* end */ +#define fatalx(msg) \ + do { \ + assertf(0, "fatal in %s: %pSQq", log_procname, \ + (const char *)msg); \ + __builtin_unreachable(); \ + } while (0) \ + /* end */ #endif /* LOG_H */ -- cgit v1.2.3