]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
log: propagate max log level into glibc's setlogmask()
authorLennart Poettering <lennart@poettering.net>
Tue, 23 May 2023 07:27:01 +0000 (09:27 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 23 May 2023 16:53:58 +0000 (09:53 -0700)
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.

src/basic/log.c

index 4cd2d5a4ab6667fb081e8a95f68a3463cd4716e3..dc88b70d7577d28a8acc3f4453f294b74739c4ef 100644 (file)
@@ -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) {