richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
923a60
From 80f0fa4a77bfceab3bae7cf67f44b8f899b22427 Mon Sep 17 00:00:00 2001
923a60
From: Vito Caputo <vcaputo@gnugeneration.com>
923a60
Date: Tue, 18 Jul 2017 18:00:37 +0200
923a60
Subject: [PATCH] journal: implicitly flush to var on recovery (#4028)
923a60
923a60
When the system journal becomes re-opened post-flush with the runtime
923a60
journal open, it implies we've recovered from something like an ENOSPC
923a60
situation where the system journal rotate had failed, leaving the system
923a60
journal closed, causing the runtime journal to be opened post-flush.
923a60
923a60
For the duration of the unavailable system journal, we log to the
923a60
runtime journal.  But when the system journal gets opened (space made
923a60
available, for example), we need to close the runtime journal before new
923a60
journal writes will go to the system journal.  Calling
923a60
server_flush_to_var() after opening the system journal with a runtime
923a60
journal present, post-flush, achieves this while preserving the runtime
923a60
journal's contents in the system journal.
923a60
923a60
The combination of the present flushed flag file and the runtime journal
923a60
being open is a state where we should be logging to the system journal,
923a60
so it's appropriate to resume doing so once we've successfully opened
923a60
the system journal.
923a60
923a60
(cherry picked from commit 929eeb5498e8ae87e05ae683c6d3014d4b59056d)
923a60
923a60
Related: #1364092
923a60
---
923a60
 src/journal/journald-server.c | 15 +++++++++++++--
923a60
 1 file changed, 13 insertions(+), 2 deletions(-)
923a60
923a60
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
923a60
index 2b7ecd09ab..3e9412d577 100644
923a60
--- a/src/journal/journald-server.c
923a60
+++ b/src/journal/journald-server.c
923a60
@@ -923,6 +923,7 @@ static int system_journal_open(Server *s, bool flush_requested) {
923a60
         char *fn;
923a60
         sd_id128_t machine;
923a60
         char ids[33];
923a60
+        bool flushed = false;
923a60
 
923a60
         r = sd_id128_get_machine(&machine);
923a60
         if (r < 0)
923a60
@@ -933,7 +934,7 @@ static int system_journal_open(Server *s, bool flush_requested) {
923a60
         if (!s->system_journal &&
923a60
             (s->storage == STORAGE_PERSISTENT || s->storage == STORAGE_AUTO) &&
923a60
             (flush_requested
923a60
-             || access("/run/systemd/journal/flushed", F_OK) >= 0)) {
923a60
+             || (flushed = (access("/run/systemd/journal/flushed", F_OK) >= 0)))) {
923a60
 
923a60
                 /* If in auto mode: first try to create the machine
923a60
                  * path, but not the prefix.
923a60
@@ -958,6 +959,16 @@ static int system_journal_open(Server *s, bool flush_requested) {
923a60
 
923a60
                         r = 0;
923a60
                 }
923a60
+
923a60
+                /* If the runtime journal is open, and we're post-flush, we're
923a60
+                 * recovering from a failed system journal rotate (ENOSPC)
923a60
+                 * for which the runtime journal was reopened.
923a60
+                 *
923a60
+                 * Perform an implicit flush to var, leaving the runtime
923a60
+                 * journal closed, now that the system journal is back.
923a60
+                 */
923a60
+                if (s->runtime_journal && flushed)
923a60
+                        (void) server_flush_to_var(s);
923a60
         }
923a60
 
923a60
         if (!s->runtime_journal &&
923a60
@@ -1230,7 +1241,7 @@ static int dispatch_sigusr1(sd_event_source *es, const struct signalfd_siginfo *
923a60
 
923a60
         log_info("Received request to flush runtime journal from PID %"PRIu32, si->ssi_pid);
923a60
 
923a60
-        server_flush_to_var(s);
923a60
+        (void) server_flush_to_var(s);
923a60
         server_sync(s);
923a60
         server_vacuum(s);
923a60