1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-10-26 08:55:18 +03:00

journalctl: fix output when --lines is used with --grep

Previously, we skip the entries before arg_lines
unconditionally, which doesn't behave correctly
when used with --grep. After this commit, when
a pattern is specified, we don't skip the entries
early, but rely on the count of the lines shown
to tell us when to stop. To achieve that we would
have to search backwards instead.

Fixes #25147

(cherry picked from commit db4691961c)
(cherry picked from commit c4cdbb978f)
(cherry picked from commit e9889190be)
(cherry picked from commit a90a4560ff)
This commit is contained in:
Mike Yuan 2023-02-18 21:49:21 +08:00 committed by Luca Boccassi
parent 8a9b918e17
commit 37b20aa49a

View File

@ -1132,6 +1132,11 @@ static int parse_argv(int argc, char *argv[]) {
r = pattern_compile(arg_pattern, flags, &arg_compiled_pattern);
if (r < 0)
return r;
/* When --grep is used along with --lines, we don't know how many lines we can print.
* So we search backwards and count until enough lines have been printed or we hit the head. */
if (arg_lines >= 0)
arg_reverse = true;
}
#endif