summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Jenkins <alan.christopher.jenkins@gmail.com>2018-02-08 09:14:32 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-02-08 09:14:32 +0100
commitb36003461a11d79d22bb48b7efe2c836fd762fc1 (patch)
tree7cfa2b6c620fae816c30c844f42f522127d928b9
parentMerge pull request #8042 from zx2c4-forks/jd/networkctl-type (diff)
downloadsystemd-b36003461a11d79d22bb48b7efe2c836fd762fc1.tar.xz
systemd-b36003461a11d79d22bb48b7efe2c836fd762fc1.zip
journal: avoid code that relies on LOG_KERN == 0 (#8110)
LOG_FAC() is the general way to extract the logging facility (when it has been combined with the logging priority). LOG_FACMASK can be used to mask off the priority so you only have the logging facility bits... but to get the logging facility e.g. LOG_USER, you also have to bitshift it as well. (The priority is in the low bits, and so only requires masking). ((priority & LOG_FACMASK) == LOG_KERN) happens to work only because LOG_KERN is 0, and hence has the same value with or without the bitshift. Code that relies on weird assumptions like this could make it harder to realize how the logging values are treated.
-rw-r--r--src/journal/journald-kmsg.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/journal/journald-kmsg.c b/src/journal/journald-kmsg.c
index 27bb7a969c..5895e48701 100644
--- a/src/journal/journald-kmsg.c
+++ b/src/journal/journald-kmsg.c
@@ -138,7 +138,7 @@ static void dev_kmsg_record(Server *s, const char *p, size_t l) {
if (r < 0 || priority < 0 || priority > 999)
return;
- if (s->forward_to_kmsg && (priority & LOG_FACMASK) != LOG_KERN)
+ if (s->forward_to_kmsg && LOG_FAC(priority) != LOG_KERN)
return;
l -= (e - p) + 1;
@@ -287,7 +287,7 @@ static void dev_kmsg_record(Server *s, const char *p, size_t l) {
if (asprintf(&syslog_facility, "SYSLOG_FACILITY=%i", LOG_FAC(priority)) >= 0)
iovec[n++] = IOVEC_MAKE_STRING(syslog_facility);
- if ((priority & LOG_FACMASK) == LOG_KERN)
+ if (LOG_FAC(priority) == LOG_KERN)
iovec[n++] = IOVEC_MAKE_STRING("SYSLOG_IDENTIFIER=kernel");
else {
pl -= syslog_parse_identifier((const char**) &p, &identifier, &pid);