From d63d5b5cd0a4a2010797b435a7fc981e4d94b05d Mon Sep 17 00:00:00 2001
From: Frantisek Sumsal <frantisek@sumsal.cz>
Date: Thu, 9 Nov 2023 13:24:57 +0100
Subject: [PATCH] journal: recalculate line_max when stdout stream state
 changes

Otherwise we might still use the more restrictive limit when we get to
STDOUT_STREAM_RUNNING, causing unexpected line breaks in the journal
messages.

Follow-up to: 80e9720616
Resolves: #29916

(cherry picked from commit d603e3d58c77c66dc411c1c5b6575c45ea1d6a8d)
(cherry picked from commit 7a7e84b01581fbe31dc9518a40a05e30a61cf3db)
(cherry picked from commit 4090c12f1263a543b9116a695fa1892d86fbb22d)

Conflict:NA
Reference:https://github.com/systemd/systemd/commit/d603e3d58c77c66dc411c1c5b6575c45ea1d6a8d
---
 src/journal/journald-stream.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c
index 9d8606f995..f2f3f0ac5b 100644
--- a/src/journal/journald-stream.c
+++ b/src/journal/journald-stream.c
@@ -488,19 +488,21 @@ static int stdout_stream_scan(
                 LineBreak force_flush,
                 size_t *ret_consumed) {
 
-        size_t consumed = 0, line_max;
+        size_t consumed = 0;
         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);
+                size_t tmp_remaining, line_max;
+
+                line_max = stdout_stream_line_max(s);
+                tmp_remaining = MIN(remaining, line_max);
 
                 end1 = memchr(p, '\n', tmp_remaining);
                 end2 = memchr(p, 0, end1 ? (size_t) (end1 - p) : tmp_remaining);
-- 
2.33.0

