Skip to content

Commit fe16729

Browse files
sourcejedikeszybz
authored andcommitted
journal: include kmsg lines from the systemd process which exec()d us (systemd#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.
1 parent 0e3c6bf commit fe16729

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/journal/journald-kmsg.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,17 @@ void server_forward_kmsg(
9898
log_debug_errno(errno, "Failed to write to /dev/kmsg for logging: %m");
9999
}
100100

101-
static bool is_us(const char *pid) {
102-
pid_t t;
101+
static bool is_us(const char *identifier, const char *pid) {
102+
pid_t pid_num;
103103

104-
assert(pid);
104+
if (!identifier || !pid)
105+
return false;
105106

106-
if (parse_pid(pid, &t) < 0)
107+
if (parse_pid(pid, &pid_num) < 0)
107108
return false;
108109

109-
return t == getpid_cached();
110+
return pid_num == getpid_cached() &&
111+
streq(identifier, program_invocation_short_name);
110112
}
111113

112114
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) {
292294

293295
/* Avoid any messages we generated ourselves via
294296
* log_info() and friends. */
295-
if (pid && is_us(pid))
297+
if (is_us(identifier, pid))
296298
goto finish;
297299

298300
if (identifier) {

0 commit comments

Comments
 (0)