From cae8edd93ca2ef90c41cb9b6322b6908d12947b5 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Tue, 17 May 2022 14:57:54 +0200 Subject: [PATCH] journal: Add new _INITRD field The _INITRD field is a boolean field (0 or 1) that specifies whether a message was processed by systemd-journald in the initrd or not. --- man/systemd.journal-fields.xml | 8 ++++++++ src/journal/journald-server.c | 5 +++++ src/journal/journald-server.h | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/man/systemd.journal-fields.xml b/man/systemd.journal-fields.xml index d50e89f0bb9..320b7829923 100644 --- a/man/systemd.journal-fields.xml +++ b/man/systemd.journal-fields.xml @@ -398,6 +398,14 @@ for details about journal namespaces. + + _SYSTEM_CONTEXT= + + A string field that specifies the context in which the message was logged. If + initrd, the log message was processed while systemd-journald + was running inside the initrd. If main, the log message was generated after + journald switched root to the root filesystem. + diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index 15b6844d5d4..0061abadff5 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -1035,6 +1035,11 @@ static void dispatch_message_real( if (!isempty(s->namespace_field)) iovec[n++] = IOVEC_MAKE_STRING(s->namespace_field); + if (in_initrd()) + iovec[n++] = IOVEC_MAKE_STRING("_SYSTEM_CONTEXT=initrd"); + else + iovec[n++] = IOVEC_MAKE_STRING("_SYSTEM_CONTEXT=main"); + assert(n <= m); if (s->split_mode == SPLIT_UID && c && uid_is_valid(c->uid)) diff --git a/src/journal/journald-server.h b/src/journal/journald-server.h index 01244e1ce10..ee8f3741908 100644 --- a/src/journal/journald-server.h +++ b/src/journal/journald-server.h @@ -179,7 +179,7 @@ struct Server { #define SERVER_MACHINE_ID(s) ((s)->machine_id_field + STRLEN("_MACHINE_ID=")) /* Extra fields for any log messages */ -#define N_IOVEC_META_FIELDS 23 +#define N_IOVEC_META_FIELDS 24 /* Extra fields for log messages that contain OBJECT_PID= (i.e. log about another process) */ #define N_IOVEC_OBJECT_FIELDS 18