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.
This commit is contained in:
Yu Watanabe
2023-09-26 13:26:22 +09:00
parent 7c1784db83
commit 304cb08f84
2 changed files with 4 additions and 8 deletions
+2 -6
View File
@@ -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),
+2 -2
View File
@@ -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)