1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-21 09:33:57 +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)
This commit is contained in:
Mike Yuan 2023-02-18 21:49:21 +08:00 committed by Zbigniew Jędrzejewski-Szmek
parent 2cf90e13f5
commit a90a4560ff

View File

@ -1139,6 +1139,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