!93 fix journald: enforce longer line length limit during "setup" phase of stream protocol
From: @fangxiuning Reviewed-by: @overweight Signed-off-by: @overweight
This commit is contained in:
commit
a9ae897c6c
@ -0,0 +1,108 @@
|
||||
From 80e9720616df0eeaba75874fd86fbfbe8b7a03a7 Mon Sep 17 00:00:00 2001
|
||||
From: Yangyang Shen <shenyangyang4@huawei.com>
|
||||
Date: Wed, 24 Mar 2021 21:23:01 +0800
|
||||
Subject: [PATCH] journald: enforce longer line length limit during "setup"
|
||||
phase of stream protocol
|
||||
|
||||
This PR made modification on Lennart Poettering's basis. Fix the LineMax's function failure problem.
|
||||
|
||||
Signed-off-by: Yangyang Shen <shenyangyang4@huawei.com>
|
||||
---
|
||||
src/journal/journald-stream.c | 35 ++++++++++++++++++++++++++++-------
|
||||
1 file changed, 28 insertions(+), 7 deletions(-)
|
||||
|
||||
diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c
|
||||
index 385dc4b..85723f5 100644
|
||||
--- a/src/journal/journald-stream.c
|
||||
+++ b/src/journal/journald-stream.c
|
||||
@@ -39,6 +39,12 @@
|
||||
|
||||
#define STDOUT_STREAMS_MAX 4096
|
||||
|
||||
+/* During the "setup" protocol phase of the stream logic let's define a different maximum line length than
|
||||
+ * during the actual operational phase. We want to allow users to specify very short line lengths after all,
|
||||
+ * but the unit name we embed in the setup protocol might be longer than that. Hence, during the setup phase
|
||||
+ * let's enforce a line length matching the maximum unit name length (255) */
|
||||
+#define STDOUT_STREAM_SETUP_PROTOCOL_LINE_MAX (UNIT_NAME_MAX-1U)
|
||||
+
|
||||
typedef enum StdoutStreamState {
|
||||
STDOUT_STREAM_IDENTIFIER,
|
||||
STDOUT_STREAM_UNIT_ID,
|
||||
@@ -47,7 +53,7 @@ typedef enum StdoutStreamState {
|
||||
STDOUT_STREAM_FORWARD_TO_SYSLOG,
|
||||
STDOUT_STREAM_FORWARD_TO_KMSG,
|
||||
STDOUT_STREAM_FORWARD_TO_CONSOLE,
|
||||
- STDOUT_STREAM_RUNNING
|
||||
+ STDOUT_STREAM_RUNNING,
|
||||
} StdoutStreamState;
|
||||
|
||||
/* The different types of log record terminators: a real \n was read, a NUL character was read, the maximum line length
|
||||
@@ -468,6 +474,18 @@ static int stdout_stream_found(
|
||||
return r;
|
||||
}
|
||||
|
||||
+static size_t stdout_stream_line_max(StdoutStream *s) {
|
||||
+ assert(s);
|
||||
+
|
||||
+ /* During the "setup" phase of our protocol, let's ensure we use a line length where a full unit name
|
||||
+ * can fit in */
|
||||
+ if (s->state != STDOUT_STREAM_RUNNING)
|
||||
+ return STDOUT_STREAM_SETUP_PROTOCOL_LINE_MAX;
|
||||
+
|
||||
+ /* After the protocol's "setup" phase is complete, let's use whatever the user configured */
|
||||
+ return s->server->line_max;
|
||||
+}
|
||||
+
|
||||
static int stdout_stream_scan(
|
||||
StdoutStream *s,
|
||||
char *p,
|
||||
@@ -475,19 +493,22 @@ static int stdout_stream_scan(
|
||||
LineBreak force_flush,
|
||||
size_t *ret_consumed) {
|
||||
|
||||
- size_t consumed = 0;
|
||||
+ size_t consumed = 0, line_max;
|
||||
int r;
|
||||
|
||||
assert(s);
|
||||
assert(p);
|
||||
|
||||
+ line_max = stdout_stream_line_max(s);
|
||||
+
|
||||
for (;;) {
|
||||
LineBreak line_break;
|
||||
size_t skip, found;
|
||||
char *end1, *end2;
|
||||
+ size_t tmp_remaining = MIN(remaining, line_max);
|
||||
|
||||
- end1 = memchr(p, '\n', remaining);
|
||||
- end2 = memchr(p, 0, end1 ? (size_t) (end1 - p) : remaining);
|
||||
+ end1 = memchr(p, '\n', tmp_remaining);
|
||||
+ end2 = memchr(p, 0, end1 ? (size_t) (end1 - p) : tmp_remaining);
|
||||
|
||||
if (end2) {
|
||||
/* We found a NUL terminator */
|
||||
@@ -499,9 +520,9 @@ static int stdout_stream_scan(
|
||||
found = end1 - p;
|
||||
skip = found + 1;
|
||||
line_break = LINE_BREAK_NEWLINE;
|
||||
- } else if (remaining >= s->server->line_max) {
|
||||
+ } else if (remaining >= line_max) {
|
||||
/* Force a line break after the maximum line length */
|
||||
- found = skip = s->server->line_max;
|
||||
+ found = skip = line_max;
|
||||
line_break = LINE_BREAK_LINE_MAX;
|
||||
} else
|
||||
break;
|
||||
@@ -563,7 +584,7 @@ static int stdout_stream_process(sd_event_source *es, int fd, uint32_t revents,
|
||||
|
||||
/* Try to make use of the allocated buffer in full, but never read more than the configured line size. Also,
|
||||
* always leave room for a terminating NUL we might need to add. */
|
||||
- limit = MIN(s->allocated - 1, s->server->line_max);
|
||||
+ limit = MIN(s->allocated - 1, MAX(s->server->line_max, STDOUT_STREAM_SETUP_PROTOCOL_LINE_MAX));
|
||||
assert(s->length <= limit);
|
||||
iovec = IOVEC_MAKE(s->buffer + s->length, limit - s->length);
|
||||
|
||||
--
|
||||
1.8.3.1
|
||||
|
||||
15
systemd.spec
15
systemd.spec
@ -20,7 +20,7 @@
|
||||
Name: systemd
|
||||
Url: https://www.freedesktop.org/wiki/Software/systemd
|
||||
Version: 248
|
||||
Release: 2
|
||||
Release: 4
|
||||
License: MIT and LGPLv2+ and GPLv2+
|
||||
Summary: System and Service Manager
|
||||
|
||||
@ -65,7 +65,9 @@ Patch0016: 0016-systemd-change-time-log-level.patch
|
||||
#Patch0017: 0017-fix-capsh-drop-but-ping-success.patch
|
||||
#Patch0018: 0018-resolved-create-etc-resolv.conf-symlink-at-runtime.patch
|
||||
#Patch0019: 0019-core-serialize-u-pids-until-the-processes-have-been-.patch
|
||||
#Patch0020: 0020-scope-on-unified-make-sure-to-unwatch-all-PIDs-once-.patch
|
||||
#Patch0020: 0020-scope-on-unified-make-sure-to-unwatch-all-PIDs-once-.patch
|
||||
|
||||
Patch6000:backport-journald-enforce-longer-line-length-limit-during-set.patch
|
||||
|
||||
BuildRequires: gcc, gcc-c++
|
||||
BuildRequires: libcap-devel, libmount-devel, pam-devel, libselinux-devel
|
||||
@ -1528,13 +1530,16 @@ fi
|
||||
%exclude /usr/share/man/man3/*
|
||||
|
||||
%changelog
|
||||
* Fri 30 Apr 2021 hexiaowen <hexiaowen@huawei.com> - 248-3
|
||||
* Wed May 19 2021 fangxiuning <fangxiuning@huawei.com> - 248-4
|
||||
- journald: enforce longer line length limit during "setup" phase of stream protocol
|
||||
|
||||
* Fri Apr 30 2021 hexiaowen <hexiaowen@huawei.com> - 248-3
|
||||
- delete unused rebase-patch
|
||||
|
||||
* Fri 30 Apr 2021 hexiaowen <hexiaowen@huawei.com> - 248-2
|
||||
* Fri Apr 30 2021 hexiaowen <hexiaowen@huawei.com> - 248-2
|
||||
- delete unused patches
|
||||
|
||||
* Fri 30 Apr 2021 hexiaowen <hexiaowen@huawei.com> - 248-1
|
||||
* Fri Apr 30 2021 hexiaowen <hexiaowen@huawei.com> - 248-1
|
||||
- Rebase to version 248
|
||||
|
||||
* Wed Mar 31 2021 fangxiuning <fangxiuning@huawei.com> - 246-15
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user