fatal: send log to logger

This commit is contained in:
Omar Polo 2021-04-28 12:43:17 +00:00
parent 42447f673f
commit d89a9060f8
1 changed files with 16 additions and 18 deletions

34
log.c
View File

@ -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)