From: Yu Watanabe Date: Sun, 24 Sep 2023 17:00:41 +0000 (+0900) Subject: sd-journal: always fallback to find entry by realtime X-Git-Tag: v255-rc1~414^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=304cb08f84b6aea8962035340c9a83f54541cf77;p=thirdparty%2Fsystemd.git sd-journal: always fallback to find entry by realtime Consider the following situation: - There are two journal files (x and y), that contains entries for two boots (X and Y). - The journal file x contains entries of the boot X, and y contains entries of Y. - Nevertheless x does not contains entries of boot Y, it contains the _BOOT_ID= data object of boot Y. Of course, the data object is not referenced by any entries in the journal file x. In such situation, when the current location of sd_journal is the head of journal y, that is, the first entry of the boot Y, sd_journal_previous() failed without this change, and 'journalctl --boot -NUM' for boot X failed. Fixes #29275. --- diff --git a/src/libsystemd/sd-journal/journal-file.c b/src/libsystemd/sd-journal/journal-file.c index ab25ff87bc3..5d3f85e4cc3 100644 --- a/src/libsystemd/sd-journal/journal-file.c +++ b/src/libsystemd/sd-journal/journal-file.c @@ -3351,10 +3351,8 @@ int journal_file_move_to_entry_by_monotonic( assert(f); r = find_data_object_by_boot_id(f, boot_id, &o, NULL); - if (r < 0) + if (r <= 0) return r; - if (r == 0) - return -ENOENT; return generic_array_bisect_plus_one( f, @@ -3546,10 +3544,8 @@ int journal_file_move_to_entry_by_monotonic_for_data( /* First, seek by time */ r = find_data_object_by_boot_id(f, boot_id, &o, &b); - if (r < 0) + if (r <= 0) return r; - if (r == 0) - return -ENOENT; r = generic_array_bisect_plus_one(f, le64toh(o->data.entry_offset), diff --git a/src/libsystemd/sd-journal/sd-journal.c b/src/libsystemd/sd-journal/sd-journal.c index 718d45af0ef..1b9dcbdecb3 100644 --- a/src/libsystemd/sd-journal/sd-journal.c +++ b/src/libsystemd/sd-journal/sd-journal.c @@ -667,7 +667,7 @@ static int find_location_for_match( return journal_file_move_to_entry_by_seqnum_for_data(f, d, j->current_location.seqnum, direction, ret, offset); if (j->current_location.monotonic_set) { r = journal_file_move_to_entry_by_monotonic_for_data(f, d, j->current_location.boot_id, j->current_location.monotonic, direction, ret, offset); - if (r != -ENOENT) + if (r != 0) return r; /* The data object might have been invalidated. */ @@ -762,7 +762,7 @@ static int find_location_with_matches( return journal_file_move_to_entry_by_seqnum(f, j->current_location.seqnum, direction, ret, offset); if (j->current_location.monotonic_set) { r = journal_file_move_to_entry_by_monotonic(f, j->current_location.boot_id, j->current_location.monotonic, direction, ret, offset); - if (r != -ENOENT) + if (r != 0) return r; } if (j->current_location.realtime_set)