From fe167298681ccc0292b72a03ba82889792a1c982 Mon Sep 17 00:00:00 2001 From: Alan Jenkins Date: Mon, 5 Feb 2018 16:53:40 +0000 Subject: [PATCH] journal: include kmsg lines from the systemd process which exec()d us (#8078) Let the journal capture messages emitted by systemd, before it ran exec("/usr/lib/systemd/systemd-journald"). Usually such messages will only appear with `systemd.log_level=debug`. kmsg lines written after the exec() will be ignored as before. In other words, we are avoiding reading our own lines, which start "systemd-journald[100]: " assuming we are PID 100. But now we will start allowing ourself to read lines which start "systemd[100]: ", or any other prefix which is not "systemd-journald[100]: ". So this can't help you see messages when we fail to exec() journald :). But, it makes it easier to see what the pre-exec() messages look like in the successful case. Comparing messages like this can be useful when debugging. Noticing weird omissions of messages, otoh, makes me anxious. --- src/journal/journald-kmsg.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/journal/journald-kmsg.c b/src/journal/journald-kmsg.c index 0fadc16..27bb7a9 100644 --- a/src/journal/journald-kmsg.c +++ b/src/journal/journald-kmsg.c @@ -98,15 +98,17 @@ void server_forward_kmsg( log_debug_errno(errno, "Failed to write to /dev/kmsg for logging: %m"); } -static bool is_us(const char *pid) { - pid_t t; +static bool is_us(const char *identifier, const char *pid) { + pid_t pid_num; - assert(pid); + if (!identifier || !pid) + return false; - if (parse_pid(pid, &t) < 0) + if (parse_pid(pid, &pid_num) < 0) return false; - return t == getpid_cached(); + return pid_num == getpid_cached() && + streq(identifier, program_invocation_short_name); } static void dev_kmsg_record(Server *s, const char *p, size_t l) { @@ -292,7 +294,7 @@ static void dev_kmsg_record(Server *s, const char *p, size_t l) { /* Avoid any messages we generated ourselves via * log_info() and friends. */ - if (pid && is_us(pid)) + if (is_us(identifier, pid)) goto finish; if (identifier) { -- 2.7.4