Skip to content

Commit

Permalink
Fix journal-reader example to point to the most recent entry and not …
Browse files Browse the repository at this point in the history
…a random one.

If next if called directly after seek tail, a random old entry is pointed.
See the implementation in journalctl:
https://github.com/systemd/systemd/blob/8389fd19d20370077f2d5601af0a089ec92ece05/src/journal/journalctl.c#L1292-L1299

And this related bug report: https://bugs.freedesktop.org/show_bug.cgi?id=64614
  • Loading branch information
romainreignier authored and codyps committed Dec 10, 2021
1 parent cbac562 commit f91a6a9
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions examples/journal-reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ mod x {
.seek(JournalSeek::Tail)
.expect("Could not seek to end of journal");

// JournalSeek::Tail goes to the position after the most recent entry so step back to
// point to the most recent entry.
reader.previous()?;

// Print up to MAX_MESSAGES incoming messages
let mut i = 0;
loop {
Expand Down

0 comments on commit f91a6a9

Please sign in to comment.