]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-journal: always fallback to find entry by realtime
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 24 Sep 2023 17:00:41 +0000 (02:00 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 26 Sep 2023 04:26:22 +0000 (13:26 +0900)
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.

src/libsystemd/sd-journal/journal-file.c
src/libsystemd/sd-journal/sd-journal.c

index ab25ff87bc3851e961cec58edfca0f18ba220635..5d3f85e4cc38f7d5eda26492bae6da33334e66f0 100644 (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),
index 718d45af0efffa01865cdcc577cd04b437abeea9..1b9dcbdecb30acd148e11487d1a8ef23023c420a 100644 (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)