From d89a9060f812301850ae4c3f975d475e31fba0a7 Mon Sep 17 00:00:00 2001 From: Omar Polo Date: Wed, 28 Apr 2021 12:43:17 +0000 Subject: [PATCH] fatal: send log to logger --- log.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/log.c b/log.c index aa0d86d..82dcc31 100644 --- a/log.c +++ b/log.c @@ -53,24 +53,6 @@ print_date(void) fprintf(stderr, "[%s] ", buf); } -void -fatal(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - - if (conf.foreground) { - print_date(); - vfprintf(stderr, fmt, ap); - fprintf(stderr, "\n"); - } else - vsyslog(LOG_DAEMON | LOG_ERR, fmt, ap); - - va_end(ap); - exit(1); -} - static inline int should_log(int priority) { @@ -97,6 +79,22 @@ send_log(int priority, const char *msg, size_t len) imsg_flush(&logibuf); } +void +fatal(const char *fmt, ...) +{ + va_list ap; + int r; + char *fmted; + + va_start(ap, fmt); + if ((r = vasprintf(&fmted, fmt, ap)) != -1) { + send_log(LOG_ERR, fmted, r+1); + free(fmted); + } + va_end(ap); + exit(1); +} + static inline void vlog(int priority, struct client *c, const char *fmt, va_list ap)