diff options
author | Lennart Poettering <lennart@poettering.net> | 2023-05-23 09:27:01 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2023-05-23 18:53:58 +0200 |
commit | 13f37e6e972d3d6beca5fc628b746e07a6523ae2 (patch) | |
tree | 7f69637ab28f70a51a942cca6a071c9fe6a84928 /src/basic/log.c | |
parent | udevadm: improve debug logging when triggering/watching events (diff) | |
download | systemd-13f37e6e972d3d6beca5fc628b746e07a6523ae2.tar.xz systemd-13f37e6e972d3d6beca5fc628b746e07a6523ae2.zip |
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.
Diffstat (limited to '')
-rw-r--r-- | src/basic/log.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/basic/log.c b/src/basic/log.c index 4cd2d5a4ab..dc88b70d75 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) { |