]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-journal: also clear saved direction on seek 29235/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 19 Sep 2023 21:36:50 +0000 (06:36 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 20 Sep 2023 16:59:21 +0000 (01:59 +0900)
Otherwise, sd_journal_previous() -> real_journal_next(DIRECTION_UP) ->
next_beyond_location() wrongly handles that previously we hit EOF of
the file, and returns 0 without finding a matching entry.

Fixes #29216.

src/journal/test-journal-interleaving.c
src/libsystemd/sd-journal/journal-file.c
src/libsystemd/sd-journal/journal-file.h

index 8dcdaecc65b7705ccd596e0580dc4d49b88c4bbe..21c5bdddae29cd3445161fe68be7154d99ee1b7b 100644 (file)
@@ -225,9 +225,8 @@ static void test_skip_one(void (*setup)(void)) {
         assert_ret(sd_journal_open_directory(&j, t, 0));
         assert_ret(sd_journal_seek_tail(j));
         assert_se(sd_journal_previous(j) == 1); /* pointing to the last entry */
-        // FIXME: the below does not work. See issue #29216.
-        //assert_ret(sd_journal_seek_tail(j));
-        //assert_se(sd_journal_previous(j) == 1); /* pointing to the last entry */
+        assert_ret(sd_journal_seek_tail(j));
+        assert_se(sd_journal_previous(j) == 1); /* pointing to the last entry */
         test_check_numbers_up(j, 9);
         sd_journal_close(j);
 
index 95cf25bff00264672e1d626657bbf57bd0d428ba..b21d29f6ea271d4aeacd264bc6d4fcecb24aa614 100644 (file)
@@ -3343,6 +3343,10 @@ void journal_file_reset_location(JournalFile *f) {
         f->current_monotonic = 0;
         zero(f->current_boot_id);
         f->current_xor_hash = 0;
+
+        /* Also reset the previous reading direction. Otherwise, next_beyond_location() may wrongly handle we
+         * already hit EOF. See issue #29216. */
+        f->last_direction = _DIRECTION_INVALID;
 }
 
 void journal_file_save_location(JournalFile *f, Object *o, uint64_t offset) {
@@ -3939,6 +3943,7 @@ int journal_file_open(
                                             MAX(MIN_COMPRESS_THRESHOLD, compress_threshold_bytes),
                 .strict_order = FLAGS_SET(file_flags, JOURNAL_STRICT_ORDER),
                 .newest_boot_id_prioq_idx = PRIOQ_IDX_NULL,
+                .last_direction = _DIRECTION_INVALID,
         };
 
         if (fname) {
index a4d8912aa8e074a2812a8c989e83dc2f0d1d29b5..b018fd8788e056d9953c30060f9caec831ee6625 100644 (file)
@@ -31,7 +31,8 @@ typedef struct JournalMetrics {
 
 typedef enum direction {
         DIRECTION_UP,
-        DIRECTION_DOWN
+        DIRECTION_DOWN,
+        _DIRECTION_INVALID = -EINVAL,
 } direction_t;
 
 typedef enum LocationType {