|
|
17b0f1 |
From 6032a92b8fb27a7c65a1853e62a142fd9a062b73 Mon Sep 17 00:00:00 2001
|
|
|
17b0f1 |
From: Lennart Poettering <lennart@poettering.net>
|
|
|
17b0f1 |
Date: Thu, 17 Aug 2017 10:21:23 +0200
|
|
|
17b0f1 |
Subject: [PATCH] journald: don't flush to /var/log/journal before we get asked
|
|
|
17b0f1 |
to
|
|
|
17b0f1 |
|
|
|
17b0f1 |
This changes journald to not write to /var/log/journal until it received
|
|
|
17b0f1 |
SIGUSR1 for the first time, thus having been requested to flush the runtime
|
|
|
17b0f1 |
journal to disk.
|
|
|
17b0f1 |
|
|
|
17b0f1 |
This makes the journal work nicer with systems which have the root file system
|
|
|
17b0f1 |
writable early, but still need to rearrange /var before journald should start
|
|
|
17b0f1 |
writing and creating files to it, for example because ACLs need to be applied
|
|
|
17b0f1 |
first, or because /var is to be mounted from another file system, NFS or tmpfs
|
|
|
17b0f1 |
(as is the case for systemd.volatile=state).
|
|
|
17b0f1 |
|
|
|
17b0f1 |
Before this change we required setupts with /var split out to mount the root
|
|
|
17b0f1 |
disk read-only early on, and ship an /etc/fstab that remounted it writable only
|
|
|
17b0f1 |
after having placed /var at the right place. But even that was racy for various
|
|
|
17b0f1 |
preparations as journald might end up accessing the file system before it was
|
|
|
17b0f1 |
entirely set up, as soon as it was writable.
|
|
|
17b0f1 |
|
|
|
17b0f1 |
With this change we make scheduling when to start writing to /var/log/journal
|
|
|
17b0f1 |
explicit. This means persistent mode now requires
|
|
|
17b0f1 |
systemd-journal-flush.service in the mix to work, as otherwise journald would
|
|
|
17b0f1 |
never write to the directory.
|
|
|
17b0f1 |
|
|
|
17b0f1 |
See: #1397
|
|
|
17b0f1 |
|
|
|
17b0f1 |
(cherry-picked from commit f78273c8dacf678cc8fd7387f678e6344a99405c)
|
|
|
17b0f1 |
|
|
|
17b0f1 |
Resolves: #1364092
|
|
|
17b0f1 |
---
|
|
|
17b0f1 |
src/journal/journald-server.c | 21 +++++++++++----------
|
|
|
17b0f1 |
src/journal/journald-server.h | 2 +-
|
|
|
17b0f1 |
src/journal/journald.c | 2 +-
|
|
|
17b0f1 |
3 files changed, 13 insertions(+), 12 deletions(-)
|
|
|
17b0f1 |
|
|
|
17b0f1 |
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
|
|
|
17b0f1 |
index 96ffda4ec9..07426b41e8 100644
|
|
|
17b0f1 |
--- a/src/journal/journald-server.c
|
|
|
17b0f1 |
+++ b/src/journal/journald-server.c
|
|
|
17b0f1 |
@@ -918,7 +918,7 @@ finish:
|
|
|
17b0f1 |
}
|
|
|
17b0f1 |
|
|
|
17b0f1 |
static bool flushed_flag_is_set(void) {
|
|
|
17b0f1 |
- return (access("/run/systemd/journal/flushed", F_OK) >= 0);
|
|
|
17b0f1 |
+ return access("/run/systemd/journal/flushed", F_OK) >= 0;
|
|
|
17b0f1 |
}
|
|
|
17b0f1 |
|
|
|
17b0f1 |
static int system_journal_open(Server *s, bool flush_requested) {
|
|
|
17b0f1 |
@@ -926,7 +926,6 @@ static int system_journal_open(Server *s, bool flush_requested) {
|
|
|
17b0f1 |
char *fn;
|
|
|
17b0f1 |
sd_id128_t machine;
|
|
|
17b0f1 |
char ids[33];
|
|
|
17b0f1 |
- bool flushed = false;
|
|
|
17b0f1 |
|
|
|
17b0f1 |
r = sd_id128_get_machine(&machine);
|
|
|
17b0f1 |
if (r < 0)
|
|
|
17b0f1 |
@@ -935,8 +934,8 @@ static int system_journal_open(Server *s, bool flush_requested) {
|
|
|
17b0f1 |
sd_id128_to_string(machine, ids);
|
|
|
17b0f1 |
|
|
|
17b0f1 |
if (!s->system_journal &&
|
|
|
17b0f1 |
- (s->storage == STORAGE_PERSISTENT || s->storage == STORAGE_AUTO) &&
|
|
|
17b0f1 |
- (flush_requested || (flushed = flushed_flag_is_set()))) {
|
|
|
17b0f1 |
+ IN_SET(s->storage, STORAGE_PERSISTENT, STORAGE_AUTO) &&
|
|
|
17b0f1 |
+ (flush_requested || flushed_flag_is_set())) {
|
|
|
17b0f1 |
|
|
|
17b0f1 |
/* If in auto mode: first try to create the machine
|
|
|
17b0f1 |
* path, but not the prefix.
|
|
|
17b0f1 |
@@ -969,8 +968,8 @@ static int system_journal_open(Server *s, bool flush_requested) {
|
|
|
17b0f1 |
* Perform an implicit flush to var, leaving the runtime
|
|
|
17b0f1 |
* journal closed, now that the system journal is back.
|
|
|
17b0f1 |
*/
|
|
|
17b0f1 |
- if (s->runtime_journal && flushed)
|
|
|
17b0f1 |
- (void) server_flush_to_var(s);
|
|
|
17b0f1 |
+ if (!flush_requested)
|
|
|
17b0f1 |
+ (void) server_flush_to_var(s, true);
|
|
|
17b0f1 |
}
|
|
|
17b0f1 |
|
|
|
17b0f1 |
if (!s->runtime_journal &&
|
|
|
17b0f1 |
@@ -1021,7 +1020,7 @@ static int system_journal_open(Server *s, bool flush_requested) {
|
|
|
17b0f1 |
return r;
|
|
|
17b0f1 |
}
|
|
|
17b0f1 |
|
|
|
17b0f1 |
-int server_flush_to_var(Server *s) {
|
|
|
17b0f1 |
+int server_flush_to_var(Server *s, bool require_flag_file) {
|
|
|
17b0f1 |
sd_id128_t machine;
|
|
|
17b0f1 |
sd_journal *j = NULL;
|
|
|
17b0f1 |
char ts[FORMAT_TIMESPAN_MAX];
|
|
|
17b0f1 |
@@ -1031,13 +1030,15 @@ int server_flush_to_var(Server *s) {
|
|
|
17b0f1 |
|
|
|
17b0f1 |
assert(s);
|
|
|
17b0f1 |
|
|
|
17b0f1 |
- if (s->storage != STORAGE_AUTO &&
|
|
|
17b0f1 |
- s->storage != STORAGE_PERSISTENT)
|
|
|
17b0f1 |
+ if (!IN_SET(s->storage, STORAGE_AUTO, STORAGE_PERSISTENT))
|
|
|
17b0f1 |
return 0;
|
|
|
17b0f1 |
|
|
|
17b0f1 |
if (!s->runtime_journal)
|
|
|
17b0f1 |
return 0;
|
|
|
17b0f1 |
|
|
|
17b0f1 |
+ if (require_flag_file && !flushed_flag_is_set())
|
|
|
17b0f1 |
+ return 0;
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
system_journal_open(s, true);
|
|
|
17b0f1 |
|
|
|
17b0f1 |
if (!s->system_journal)
|
|
|
17b0f1 |
@@ -1243,7 +1244,7 @@ static int dispatch_sigusr1(sd_event_source *es, const struct signalfd_siginfo *
|
|
|
17b0f1 |
|
|
|
17b0f1 |
log_info("Received request to flush runtime journal from PID %"PRIu32, si->ssi_pid);
|
|
|
17b0f1 |
|
|
|
17b0f1 |
- (void) server_flush_to_var(s);
|
|
|
17b0f1 |
+ (void) server_flush_to_var(s, false);
|
|
|
17b0f1 |
server_sync(s);
|
|
|
17b0f1 |
server_vacuum(s);
|
|
|
17b0f1 |
|
|
|
17b0f1 |
diff --git a/src/journal/journald-server.h b/src/journal/journald-server.h
|
|
|
17b0f1 |
index b1263a7586..7a456c2d54 100644
|
|
|
17b0f1 |
--- a/src/journal/journald-server.h
|
|
|
17b0f1 |
+++ b/src/journal/journald-server.h
|
|
|
17b0f1 |
@@ -173,6 +173,6 @@ void server_sync(Server *s);
|
|
|
17b0f1 |
void server_vacuum(Server *s);
|
|
|
17b0f1 |
void server_rotate(Server *s);
|
|
|
17b0f1 |
int server_schedule_sync(Server *s, int priority);
|
|
|
17b0f1 |
-int server_flush_to_var(Server *s);
|
|
|
17b0f1 |
+int server_flush_to_var(Server *s, bool require_flag_file);
|
|
|
17b0f1 |
void server_maybe_append_tags(Server *s);
|
|
|
17b0f1 |
int server_process_datagram(sd_event_source *es, int fd, uint32_t revents, void *userdata);
|
|
|
17b0f1 |
diff --git a/src/journal/journald.c b/src/journal/journald.c
|
|
|
17b0f1 |
index 80f4634f67..15bbcbe3de 100644
|
|
|
17b0f1 |
--- a/src/journal/journald.c
|
|
|
17b0f1 |
+++ b/src/journal/journald.c
|
|
|
17b0f1 |
@@ -58,7 +58,7 @@ int main(int argc, char *argv[]) {
|
|
|
17b0f1 |
goto finish;
|
|
|
17b0f1 |
|
|
|
17b0f1 |
server_vacuum(&server);
|
|
|
17b0f1 |
- server_flush_to_var(&server);
|
|
|
17b0f1 |
+ server_flush_to_var(&server, true);
|
|
|
17b0f1 |
server_flush_dev_kmsg(&server);
|
|
|
17b0f1 |
|
|
|
17b0f1 |
log_debug("systemd-journald running as pid "PID_FMT, getpid());
|