From b43a41df6a5a72b22b6c16d5ac45d0d66a9d5207 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 2 Dec 2022 11:45:10 +0100 Subject: [PATCH] =?UTF-8?q?log:=20don=E2=80=99t=20default=20to=20syslog=20?= =?UTF-8?q?enabled?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Initialize the global ‘do_syslog’ variable to false. This ensures any log calls done before log_init() has been called (e.g. unit tests) doesn’t syslog anything. As a side effect, such log calls no longer open an implicit syslog file descriptor; this is how this “bug” was found: valgrind detected an unclosed file descriptor at exit. Finally, completely disable syslogging if log-level is “none”. --- log.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/log.c b/log.c index b93b2cde..360ca1c0 100644 --- a/log.c +++ b/log.c @@ -15,7 +15,7 @@ #include "xsnprintf.h" static bool colorize = false; -static bool do_syslog = true; +static bool do_syslog = false; static enum log_class log_level = LOG_CLASS_NONE; static const struct { @@ -45,8 +45,13 @@ log_init(enum log_colorize _colorize, bool _do_syslog, log_level = _log_level; int slvl = log_level_map[_log_level].syslog_equivalent; - if (do_syslog && slvl != -1) { + if (slvl < 0) + do_syslog = false; + + if (do_syslog) { openlog(NULL, /*LOG_PID*/0, facility_map[syslog_facility]); + + xassert(slvl >= 0); setlogmask(LOG_UPTO(slvl)); } }