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
-7
View File
@@ -164,13 +164,6 @@ set -o pipefail
# https://github.com/systemd/systemd/issues/26746
rm -f /tmp/issue-26746-log /tmp/issue-26746-cursor
ID=$(systemd-id128 new)
# FIXME:
# After the commit 7a4ee861615101ddd2f95056cf30e69e41da86ce,
# journalctl --follow does not work if no matching entry stored in the journal.
# To workaround the issue, we need to add an entry before calling journalctl below.
systemd-cat -t "$ID" /bin/sh -c 'echo aaa'
journalctl -t "$ID" --follow --cursor-file=/tmp/issue-26746-cursor | tee /tmp/issue-26746-log &
systemd-cat -t "$ID" /bin/sh -c 'echo hogehoge'
# shellcheck disable=SC2016