]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journald: always unset flushed flag when the runtime journal is opened
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 24 May 2024 21:02:39 +0000 (06:02 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 25 May 2024 18:11:24 +0000 (03:11 +0900)
If the runtime journal is opened, we will anyway write journal entries
to the runtime journal, even if the persistent journal is writable.
Hence, we need to flush the runtime journal file later.

src/journal/journald-server.c

index 4f8cff29d4ef98ae1775f9d765942848c054ec93..717c8e480e5e042b40f81d1216f99ca9f71e2bc1 100644 (file)
@@ -335,6 +335,20 @@ static bool server_flushed_flag_is_set(Server *s) {
         return access(fn, F_OK) >= 0;
 }
 
+static void server_drop_flushed_flag(Server *s) {
+        const char *fn;
+
+        assert(s);
+
+        if (s->namespace)
+                return;
+
+        fn = strjoina(s->runtime_directory, "/flushed");
+        if (unlink(fn) < 0 && errno != ENOENT)
+                log_ratelimit_warning_errno(errno, JOURNAL_LOG_RATELIMIT,
+                                            "Failed to unlink %s, ignoring: %m", fn);
+}
+
 static int server_system_journal_open(
                 Server *s,
                 bool flush_requested,
@@ -437,6 +451,7 @@ static int server_system_journal_open(
                         server_add_acls(s->runtime_journal, 0);
                         (void) cache_space_refresh(s, &s->runtime_storage);
                         patch_min_use(&s->runtime_storage);
+                        server_drop_flushed_flag(s);
                 }
         }
 
@@ -1450,7 +1465,6 @@ finish:
 }
 
 static int server_relinquish_var(Server *s) {
-        const char *fn;
         assert(s);
 
         if (s->storage == STORAGE_NONE)
@@ -1470,11 +1484,6 @@ static int server_relinquish_var(Server *s) {
         ordered_hashmap_clear_with_destructor(s->user_journals, journal_file_offline_close);
         set_clear_with_destructor(s->deferred_closes, journal_file_offline_close);
 
-        fn = strjoina(s->runtime_directory, "/flushed");
-        if (unlink(fn) < 0 && errno != ENOENT)
-                log_ratelimit_warning_errno(errno, JOURNAL_LOG_RATELIMIT,
-                                            "Failed to unlink %s, ignoring: %m", fn);
-
         server_refresh_idle_timer(s);
         return 0;
 }