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.
This commit is contained in:
parent
0e3c6bf0ce
commit
fe16729868
|
@ -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 (parse_pid(pid, &t) < 0)
|
||||
if (!identifier || !pid)
|
||||
return false;
|
||||
|
||||
return t == getpid_cached();
|
||||
if (parse_pid(pid, &pid_num) < 0)
|
||||
return false;
|
||||
|
||||
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) {
|
||||
|
|
Loading…
Reference in a new issue