1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-31 14:50:15 +03:00

Merge pull request #29017 from msizanoen1/fix-onboot-rotate

journal: Relax boot ID and monotonic clock consistency checks
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2023-09-02 14:26:44 +03:00 committed by GitHub
commit a53dc9b130
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 18 deletions

View File

@ -871,12 +871,12 @@ static bool shall_try_append_again(JournalFile *f, int r) {
log_ratelimit_info_errno(r, JOURNAL_LOG_RATELIMIT, "%s: Realtime clock jumped backwards relative to last journal entry, rotating.", f->path);
return true;
case -EREMOTE: /* Boot ID different from the one of the last entry */
log_ratelimit_info_errno(r, JOURNAL_LOG_RATELIMIT, "%s: Boot ID changed since last record, rotating.", f->path);
return true;
case -ENOTNAM: /* Monotonic time (CLOCK_MONOTONIC) jumped backwards relative to last journal entry */
log_ratelimit_info_errno(r, JOURNAL_LOG_RATELIMIT, "%s: Monotonic clock jumped backwards relative to last journal entry, rotating.", f->path);
case -ENOTNAM: /* Monotonic time (CLOCK_MONOTONIC) jumped backwards relative to last journal entry with the same boot ID */
log_ratelimit_info_errno(
r,
JOURNAL_LOG_RATELIMIT,
"%s: Monotonic clock jumped backwards relative to last journal entry with the same boot ID, rotating.",
f->path);
return true;
case -EILSEQ: /* seqnum ID last used in the file doesn't match the one we'd passed when writing an entry to it */

View File

@ -572,6 +572,10 @@ static int journal_file_verify_header(JournalFile *f) {
if (journal_file_writable(f) && header_size != sizeof(Header))
return -EPROTONOSUPPORT;
/* Don't write to journal files without the new boot ID update behavior guarantee. */
if (journal_file_writable(f) && !JOURNAL_HEADER_TAIL_ENTRY_BOOT_ID(f->header))
return -EPROTONOSUPPORT;
if (JOURNAL_HEADER_SEALED(f->header) && !JOURNAL_HEADER_CONTAINS(f->header, n_entry_arrays))
return -EBADMSG;
@ -2283,18 +2287,15 @@ static int journal_file_append_entry_internal(
"timestamp %" PRIu64 ", refusing entry.",
ts->realtime, le64toh(f->header->tail_entry_realtime));
if (!sd_id128_is_null(f->header->tail_entry_boot_id) && boot_id) {
if (!sd_id128_equal(f->header->tail_entry_boot_id, *boot_id))
return log_debug_errno(SYNTHETIC_ERRNO(EREMOTE),
"Boot ID to write is different from previous boot id, refusing entry.");
if (ts->monotonic < le64toh(f->header->tail_entry_monotonic))
return log_debug_errno(SYNTHETIC_ERRNO(ENOTNAM),
"Monotonic timestamp %" PRIu64 " smaller than previous monotonic "
"timestamp %" PRIu64 ", refusing entry.",
ts->monotonic, le64toh(f->header->tail_entry_monotonic));
}
if ((!boot_id || sd_id128_equal(*boot_id, f->header->tail_entry_boot_id)) &&
ts->monotonic < le64toh(f->header->tail_entry_monotonic))
return log_debug_errno(
SYNTHETIC_ERRNO(ENOTNAM),
"Monotonic timestamp %" PRIu64
" smaller than previous monotonic timestamp %" PRIu64
" while having the same boot ID, refusing entry.",
ts->monotonic,
le64toh(f->header->tail_entry_monotonic));
}
if (seqnum_id) {