mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-03-11 04:58:19 +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 db4691961ca52759fe6645d0fddb659ee4299ac2) (cherry picked from commit c4cdbb978f681e7356c6c6367c1730d156a6a4e0) (cherry picked from commit e9889190bea734566e778a60a1dc337e9c7ad18d)
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…
x
Reference in New Issue
Block a user