From e496036b592c7c6d1bc419b5683a6a25bf46e193 Mon Sep 17 00:00:00 2001 From: Diego Santa Cruz Date: Wed, 9 Sep 2020 16:16:49 +0000 Subject: llmnrd: add command line option to log to syslog instead of stdio When llmnrd daemonizes stdout and stderr are redirected to /dev/null and all logs are lost. This adds a cli option -s / --syslog to send the logs to syslog instead. Signed-off-by: Diego Santa Cruz --- log.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 log.c (limited to 'log.c') diff --git a/log.c b/log.c new file mode 100644 index 0000000..603db7f --- /dev/null +++ b/log.c @@ -0,0 +1,39 @@ +#include +#include + +#include "log.h" + +static bool use_syslog; + +void log_lvl(int lvl, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + + if (!use_syslog) { + FILE *out = stderr; + switch (lvl) { + case LOG_ERR: + fputs("Error: ", stderr); + break; + case LOG_WARNING: + fputs("Warning: ", stderr); + break; + case LOG_INFO: + case LOG_DEBUG: + out = stdout; + break; + } + vfprintf(out, fmt, ap); + } else { + vsyslog(lvl, fmt, ap); + } + + va_end(ap); +} + +void log_to_syslog(void) +{ + use_syslog = true; +} -- cgit v1.2.3-54-g00ecf