1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-23 21:35:11 +03:00

sd-journal: also clear saved direction on seek

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.
This commit is contained in:
Yu Watanabe 2023-09-20 06:36:50 +09:00
parent 45689fd265
commit 4aa33df845
3 changed files with 9 additions and 4 deletions

View 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);

View 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) {

View 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 {