journalctl: fix --follow with non-matching filter

When there is no matching entry stored in journal, then initial call of
`sd_journal_previous()` following `sd_journal_seek_tail()` returns
zero, and does not move the read pointer.
In the main loop, on every journal event, we call `sd_journal_next()`,
even though the current location is tail, and it takes no effect.

In such a case, we need to call `sd_journal_previous()` instead of
`sd_journal_next()`.
This commit is contained in:
Yu Watanabe
2023-05-28 23:53:58 +09:00
parent b78f9481bc
commit 80ec3db5c7
2 changed files with 1 additions and 11 deletions
+1 -4
View File
@@ -2146,10 +2146,7 @@ static int show(Context *c) {
size_t highlight[2] = {};
if (c->need_seek) {
if (!arg_reverse)
r = sd_journal_next(j);
else
r = sd_journal_previous(j);
r = sd_journal_step_one(j, !arg_reverse);
if (r < 0)
return log_error_errno(r, "Failed to iterate through journal: %m");
if (r == 0)