From: Lennart Poettering Date: Tue, 23 May 2023 07:27:01 +0000 (+0200) Subject: log: propagate max log level into glibc's setlogmask() X-Git-Tag: v254-rc1~409 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=13f37e6e972d3d6beca5fc628b746e07a6523ae2;p=thirdparty%2Fsystemd.git log: propagate max log level into glibc's setlogmask() Follow-up for: #27734 It makes sense to propagate the select log level we maintain also into glibc, so that any code that uses syslog() directly that ends up in our processes (libraries and such) are affected by our settings the same way as we are ourselves. --- diff --git a/src/basic/log.c b/src/basic/log.c index 4cd2d5a4ab6..dc88b70d757 100644 --- a/src/basic/log.c +++ b/src/basic/log.c @@ -380,6 +380,17 @@ void log_set_max_level(int level) { assert(level == LOG_NULL || (level & LOG_PRIMASK) == level); log_max_level = level; + + /* Also propagate max log level to libc's syslog(), just in case some other component loaded into our + * process logs directly via syslog(). You might wonder why we maintain our own log level variable if + * libc has the same functionality. This has multiple reasons, first and foremost that we want to + * apply this to all our log targets, not just syslog and console. Moreover, we cannot query the + * current log mask from glibc without changing it, but that's useful for testing the current log + * level before even entering the log functions like we do in our macros. */ + setlogmask(LOG_UPTO(level)); + + /* Ensure that our own LOG_NULL define maps sanely to the log mask */ + assert_cc(LOG_UPTO(LOG_NULL) == 0); } void log_set_facility(int facility) {