]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journalctl: never fail at flushing when the flushed flag is set
authorFranck Bui <fbui@suse.com>
Wed, 4 Aug 2021 09:20:07 +0000 (11:20 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 15 Sep 2021 13:10:15 +0000 (15:10 +0200)
Even if journald was not running, flushing the volatile journal used to work if
the journal was already flushed (ie the flushed flag
/run/systemd/journald/flushed was created).

However since commit 4f413af2a0a, this behavior changed and now '--flush' fails
because it tries to contact journald without checking the presence of the
flushed flag anymore.

This patch restores the previous behavior since there's no reason to fail when
journalctl can figure out that the flush is not necessary.

src/journal/journalctl.c

index 4a2343a63ddf383a3f02d3cf8f6e92ca6c188881..73e4fafdffdfcce3cffbe4698bb0160df13b97bd 100644 (file)
@@ -2064,6 +2064,11 @@ static int simple_varlink_call(const char *option, const char *method) {
 }
 
 static int flush_to_var(void) {
+        if (access("/run/systemd/journal/flushed", F_OK) >= 0)
+                return 0; /* Already flushed, no need to contact journald */
+        if (errno != ENOENT)
+                return log_error_errno(errno, "Unable to check for existence of /run/systemd/journal/flushed: %m");
+
         return simple_varlink_call("--flush", "io.systemd.Journal.FlushToVar");
 }