From c673fd52e048138a6786fb9114c1ddbf0057d6fb Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Thu, 23 Mar 2023 22:17:40 +0800 Subject: [PATCH] journalctl: fix when --grep is used with --follow Follow-up for #25147 (db4691961ca52759fe6645d0fddb659ee4299ac2) --follow sets arg_lines to 10, which breaks --grep as the latter implies --reverse. So let's not set --reverse if --follow is used. --- src/journal/journalctl.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 69b40e68ea2..97e9c1aafc4 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -1086,8 +1086,10 @@ static int parse_argv(int argc, char *argv[]) { 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) + * So we search backwards and count until enough lines have been printed or we hit the head. + * An exception is that --follow might set arg_lines, so let's not imply --reverse + * if that is specified. */ + if (arg_lines >= 0 && !arg_follow) arg_reverse = true; } -- 2.47.3