diff --git a/src/libsystemd/sd-journal/journal-file.c b/src/libsystemd/sd-journal/journal-file.c index b1064a69820..c4971a807c7 100644 --- a/src/libsystemd/sd-journal/journal-file.c +++ b/src/libsystemd/sd-journal/journal-file.c @@ -3193,56 +3193,6 @@ void journal_file_save_location(JournalFile *f, Object *o, uint64_t offset) { f->current_xor_hash = le64toh(o->entry.xor_hash); } -int journal_file_compare_locations(JournalFile *af, JournalFile *bf) { - int r; - - assert(af); - assert(af->header); - assert(bf); - assert(bf->header); - assert(af->location_type == LOCATION_SEEK); - assert(bf->location_type == LOCATION_SEEK); - - /* If contents, timestamps and seqnum match, these entries are - * identical. */ - if (sd_id128_equal(af->current_boot_id, bf->current_boot_id) && - af->current_monotonic == bf->current_monotonic && - af->current_realtime == bf->current_realtime && - af->current_xor_hash == bf->current_xor_hash && - sd_id128_equal(af->header->seqnum_id, bf->header->seqnum_id) && - af->current_seqnum == bf->current_seqnum) - return 0; - - if (sd_id128_equal(af->header->seqnum_id, bf->header->seqnum_id)) { - - /* If this is from the same seqnum source, compare - * seqnums */ - r = CMP(af->current_seqnum, bf->current_seqnum); - if (r != 0) - return r; - - /* Wow! This is weird, different data but the same - * seqnums? Something is borked, but let's make the - * best of it and compare by time. */ - } - - if (sd_id128_equal(af->current_boot_id, bf->current_boot_id)) { - - /* If the boot id matches, compare monotonic time */ - r = CMP(af->current_monotonic, bf->current_monotonic); - if (r != 0) - return r; - } - - /* Otherwise, compare UTC time */ - r = CMP(af->current_realtime, bf->current_realtime); - if (r != 0) - return r; - - /* Finally, compare by contents */ - return CMP(af->current_xor_hash, bf->current_xor_hash); -} - static bool check_properly_ordered(uint64_t new_offset, uint64_t old_offset, direction_t direction) { /* Consider it an error if any of the two offsets is uninitialized */ diff --git a/src/libsystemd/sd-journal/journal-file.h b/src/libsystemd/sd-journal/journal-file.h index c1f1ab4e4fc..2a0691ae194 100644 --- a/src/libsystemd/sd-journal/journal-file.h +++ b/src/libsystemd/sd-journal/journal-file.h @@ -275,7 +275,6 @@ int journal_file_find_field_object_with_hash(JournalFile *f, const void *field, void journal_file_reset_location(JournalFile *f); void journal_file_save_location(JournalFile *f, Object *o, uint64_t offset); -int journal_file_compare_locations(JournalFile *af, JournalFile *bf); int journal_file_next_entry(JournalFile *f, uint64_t p, direction_t direction, Object **ret_object, uint64_t *ret_offset); int journal_file_next_entry_for_data(JournalFile *f, Object *d, direction_t direction, Object **ret_object, uint64_t *ret_offset); diff --git a/src/libsystemd/sd-journal/sd-journal.c b/src/libsystemd/sd-journal/sd-journal.c index afbf2552663..053149d6750 100644 --- a/src/libsystemd/sd-journal/sd-journal.c +++ b/src/libsystemd/sd-journal/sd-journal.c @@ -801,6 +801,51 @@ static int next_beyond_location(sd_journal *j, JournalFile *f, direction_t direc } } +static int compare_locations(JournalFile *af, JournalFile *bf) { + int r; + + assert(af); + assert(af->header); + assert(bf); + assert(bf->header); + assert(af->location_type == LOCATION_SEEK); + assert(bf->location_type == LOCATION_SEEK); + + /* If contents, timestamps and seqnum match, these entries are identical. */ + if (sd_id128_equal(af->current_boot_id, bf->current_boot_id) && + af->current_monotonic == bf->current_monotonic && + af->current_realtime == bf->current_realtime && + af->current_xor_hash == bf->current_xor_hash && + sd_id128_equal(af->header->seqnum_id, bf->header->seqnum_id) && + af->current_seqnum == bf->current_seqnum) + return 0; + + if (sd_id128_equal(af->header->seqnum_id, bf->header->seqnum_id)) { + /* If this is from the same seqnum source, compare seqnums */ + r = CMP(af->current_seqnum, bf->current_seqnum); + if (r != 0) + return r; + + /* Wow! This is weird, different data but the same seqnums? Something is borked, but let's + * make the best of it and compare by time. */ + } + + if (sd_id128_equal(af->current_boot_id, bf->current_boot_id)) { + /* If the boot id matches, compare monotonic time */ + r = CMP(af->current_monotonic, bf->current_monotonic); + if (r != 0) + return r; + } + + /* Otherwise, compare UTC time */ + r = CMP(af->current_realtime, bf->current_realtime); + if (r != 0) + return r; + + /* Finally, compare by contents */ + return CMP(af->current_xor_hash, bf->current_xor_hash); +} + static int real_journal_next(sd_journal *j, direction_t direction) { JournalFile *new_file = NULL; unsigned n_files; @@ -834,7 +879,7 @@ static int real_journal_next(sd_journal *j, direction_t direction) { else { int k; - k = journal_file_compare_locations(f, new_file); + k = compare_locations(f, new_file); found = direction == DIRECTION_DOWN ? k < 0 : k > 0; }