summaryrefslogtreecommitdiffstats
path: root/src/shared/logs-show.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2024-04-26 05:10:39 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2024-05-10 04:43:57 +0200
commit87dfaba7e9d20d2e94cebc0a3f9fcb807d5473f5 (patch)
tree539142c9189b2ee7c51842d8cc365611705ecfb5 /src/shared/logs-show.c
parentjournalctl: fix --boot=0 with --file=- (from stdin) (diff)
downloadsystemd-87dfaba7e9d20d2e94cebc0a3f9fcb807d5473f5.tar.xz
systemd-87dfaba7e9d20d2e94cebc0a3f9fcb807d5473f5.zip
logs-show: flush matches before and after finding boots
Otherwise, if several matches already set, then the first seek to head or tail may move the cursor to an invalid place, hence they provide wrong ID(s). Also, reading journal after calling these function may provide unexpected data. Currently, the caller does not install any matches before calling the functions, and does not read any journal entry after journal_get_boots() succeeds or journal_find_boot_by_offset() succeeds with 0. Hence, this should not change any behavior. Just for safety.
Diffstat (limited to '')
-rw-r--r--src/shared/logs-show.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c
index 5bce1c34fb..be797afdf6 100644
--- a/src/shared/logs-show.c
+++ b/src/shared/logs-show.c
@@ -1790,6 +1790,7 @@ static int discover_next_boot(
if (r < 0)
return r;
if (r == 0) {
+ sd_journal_flush_matches(j);
*ret = (BootId) {};
return 0; /* End of journal, yay. */
}
@@ -1947,6 +1948,8 @@ int journal_find_boot_by_offset(sd_journal *j, int offset, sd_id128_t *ret) {
* (chronological) first boot in the journal. */
advance_older = offset <= 0;
+ sd_journal_flush_matches(j);
+
if (advance_older)
r = sd_journal_seek_tail(j); /* seek to newest */
else
@@ -1992,6 +1995,8 @@ int journal_get_boots(sd_journal *j, BootId **ret_boots, size_t *ret_n_boots) {
assert(ret_boots);
assert(ret_n_boots);
+ sd_journal_flush_matches(j);
+
r = sd_journal_seek_head(j); /* seek to oldest */
if (r < 0)
return r;