From 379864f89079a92ff09917e25b3aea0fadd228ac Mon Sep 17 00:00:00 2001 From: Richard Phibel Date: Mon, 5 Dec 2022 13:40:41 +0100 Subject: [PATCH] log: Switch logging to runtime when FS becomes read-only The journal has a mechanism to log to the runtime journal if it fails to log to the system journal. This mechanism is not triggered when the file system becomes read-only. We enable it here. When appending an entry fails if shall_try_append_again returns true, the journal is rotated. If the FS is read-only, rotation will fail and s->system_journal will be set to NULL. After that, when find_journal will try to open the journal since s->system_journal will be NULL, it will open the runtime journal. --- src/journal/journald-server.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index a223f4fb2b..928e07104b 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -801,6 +801,14 @@ static bool shall_try_append_again(JournalFile *f, int r) { log_debug("%s: Allocation limit reached, rotating.", f->path); return true; + case -EROFS: /* Read-only file system */ + /* When appending an entry fails if shall_try_append_again returns true, the journal is + * rotated. If the FS is read-only, rotation will fail and s->system_journal will be set to + * NULL. After that, when find_journal will try to open the journal since s->system_journal + * will be NULL, it will open the runtime journal. */ + log_ratelimit_warning(JOURNALD_LOG_RATELIMIT, "%s: Read-only file system, rotating.", f->path); + return true; + case -EIO: /* I/O error of some kind (mmap) */ log_ratelimit_warning(JOURNAL_LOG_RATELIMIT, "%s: IO error, rotating.", f->path); return true; -- 2.25.1