-
Notifications
You must be signed in to change notification settings - Fork 1
/
0002-journal-Add-option-to-skip-boot-kmsg-events.patch
112 lines (99 loc) · 4.75 KB
/
0002-journal-Add-option-to-skip-boot-kmsg-events.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
From 6eb73bc2f4ad086d6650d567454b2a5d0b4b7ea2 Mon Sep 17 00:00:00 2001
From: Dimitri John Ledkov <[email protected]>
Date: Tue, 23 Jun 2015 11:25:41 +0100
Subject: [PATCH 02/38] journal: Add option to skip boot kmsg events
The `BootKMsg` boolean is added. It defaults to `true` in the default
system namespace, and doesn't change the default behavior of the
journal.
If set to `false`, then, when `systemd-journald` starts in the default
namespace, it will ignore any existing message in the `kmsg` ring buffer
and not insert these into the journal. We do this to reduce the time
needed for the journal to start and reduce CPU overhead, since the
kernel ring buffer can be large, and contain information that the user
perhaps does not care about (e.g. initcall debug output).
The information remains accessible through `dmesg` in case it needs
to be retrieved later. This contains code originally added to
ClearLinux by Dimitri -xnox- Ledkov in 2015.
Signed-off-by: Auke Kok <[email protected]>
Cc: Dimitri John Ledkov <[email protected]>
---
man/journald.conf.xml | 9 +++++++++
src/journal/journald-gperf.gperf | 1 +
src/journal/journald-kmsg.c | 11 +++++++++++
src/journal/journald-server.c | 2 +-
src/journal/journald-server.h | 1 +
5 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/man/journald.conf.xml b/man/journald.conf.xml
index 4b0dd90cbb..e602f80541 100644
--- a/man/journald.conf.xml
+++ b/man/journald.conf.xml
@@ -429,6 +429,15 @@
messages. Defaults to on.</para></listitem>
</varlistentry>
+ <varlistentry>
+ <term><varname>BootKMsg=</varname></term>
+
+ <listitem><para>Takes a boolean value. If enabled <command>systemd-journal</command> processes
+ <filename>/dev/kmsg</filename> messages generated by the kernel before it started. If disabled,
+ those messages are not read and can be obtained by other means, like <command>dmesg</command>.
+ In the default journal namespace this option is enabled by default, it is disabled in all others.</para></listitem>
+ </varlistentry>
+
<varlistentry>
<term><varname>TTYPath=</varname></term>
diff --git a/src/journal/journald-gperf.gperf b/src/journal/journald-gperf.gperf
index 9076597628..76fa93a60c 100644
--- a/src/journal/journald-gperf.gperf
+++ b/src/journal/journald-gperf.gperf
@@ -24,6 +24,7 @@ Journal.Compress, config_parse_compress, 0, offsetof(Server, compres
Journal.Seal, config_parse_bool, 0, offsetof(Server, seal)
Journal.ReadKMsg, config_parse_bool, 0, offsetof(Server, read_kmsg)
Journal.Audit, config_parse_tristate, 0, offsetof(Server, set_audit)
+Journal.BootKMsg, config_parse_bool, 0, offsetof(Server, boot_kmsg)
Journal.SyncIntervalSec, config_parse_sec, 0, offsetof(Server, sync_interval_usec)
# The following is a legacy name for compatibility
Journal.RateLimitInterval, config_parse_sec, 0, offsetof(Server, ratelimit_interval)
diff --git a/src/journal/journald-kmsg.c b/src/journal/journald-kmsg.c
index 1b79e9366c..75387c38cd 100644
--- a/src/journal/journald-kmsg.c
+++ b/src/journal/journald-kmsg.c
@@ -398,6 +398,17 @@ int server_open_dev_kmsg(Server *s) {
if (!s->read_kmsg)
return 0;
+ if (!s->boot_kmsg) {
+ /* clear out /dev/kmsg, we don't want all its messages */
+ char buffer[40960];
+ while (1) {
+ int ret;
+ ret = read(s->dev_kmsg_fd, buffer, 40960);
+ if (ret <= 0)
+ break;
+ }
+ }
+
r = sd_event_add_io(s->event, &s->dev_kmsg_event_source, s->dev_kmsg_fd, EPOLLIN, dispatch_dev_kmsg, s);
if (r < 0) {
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
index dc9433701d..18e3c18b8e 100644
--- a/src/journal/journald-server.c
+++ b/src/journal/journald-server.c
@@ -2329,7 +2329,7 @@ int server_init(Server *s, const char *namespace) {
return r;
/* By default, only read from /dev/kmsg if are the main namespace */
- s->read_kmsg = !s->namespace;
+ s->boot_kmsg = s->read_kmsg = !s->namespace;
s->storage = s->namespace ? STORAGE_PERSISTENT : STORAGE_AUTO;
journal_reset_metrics(&s->system_storage.metrics);
diff --git a/src/journal/journald-server.h b/src/journal/journald-server.h
index ea51515db3..f472f64635 100644
--- a/src/journal/journald-server.h
+++ b/src/journal/journald-server.h
@@ -109,6 +109,7 @@ struct Server {
bool seal;
bool read_kmsg;
int set_audit;
+ bool boot_kmsg;
bool forward_to_kmsg;
bool forward_to_syslog;
--
2.36.1