From 3148edb25424a5fbb59df7994f5dc22a0d71a5f4 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 25 May 2024 06:02:39 +0900 Subject: [PATCH] journald: always unset flushed flag when the runtime journal is opened 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 | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index 4f8cff29d4e..717c8e480e5 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -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; } -- 2.47.3