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 commitdb4691961c
) (cherry picked from commitc4cdbb978f
) (cherry picked from commite9889190be
)
This commit is contained in:
parent
2cf90e13f5
commit
a90a4560ff
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user