chiark / gitweb /
journal: replace implicit flushing of journal by explicit one
authorLennart Poettering <lennart@poettering.net>
Wed, 11 Jul 2012 00:41:16 +0000 (02:41 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 11 Jul 2012 00:41:16 +0000 (02:41 +0200)
The old automatism that the flushing of the journal from /run to /var
was triggered by the appearance of /var/log/journal is broken if that
directory is mounted from another host and hence always available to be
useful as mount point. To avoid probelsm with this, introduce a new unit
that is explicitly orderer after all mounte files systems and triggers
the flushing.

Makefile.am
src/journal/journald.c
units/.gitignore
units/systemd-journal-flush.service.in [new file with mode: 0644]
units/systemd-journald.service.in

index 70b8b091e1e2d3305a0bfed76837f93c3a7cebeb..6b10f60577d864118f451d845c3abbc1f57e8bbf 100644 (file)
@@ -2331,7 +2331,8 @@ dist_systemunit_DATA += \
        units/systemd-journald.socket
 
 nodist_systemunit_DATA += \
        units/systemd-journald.socket
 
 nodist_systemunit_DATA += \
-       units/systemd-journald.service
+       units/systemd-journald.service \
+       units/systemd-journal-flush.service
 
 dist_pkgsysconf_DATA += \
        src/journal/journald.conf
 
 dist_pkgsysconf_DATA += \
        src/journal/journald.conf
@@ -2357,6 +2358,7 @@ EXTRA_DIST += \
        src/journal/libsystemd-journal.pc.in \
        src/journal/libsystemd-journal.sym \
        units/systemd-journald.service.in \
        src/journal/libsystemd-journal.pc.in \
        src/journal/libsystemd-journal.sym \
        units/systemd-journald.service.in \
+       units/systemd-journal-flush.service.in \
        src/journal/journald-gperf.gperf
 
 CLEANFILES += \
        src/journal/journald-gperf.gperf
 
 CLEANFILES += \
index da9f52813dbf2a030634d6143e81a64771291f6c..2402f7f6d083d92c9782329fbf5ab77889f741f6 100644 (file)
@@ -69,8 +69,6 @@
 
 #define RECHECK_AVAILABLE_SPACE_USEC (30*USEC_PER_SEC)
 
 
 #define RECHECK_AVAILABLE_SPACE_USEC (30*USEC_PER_SEC)
 
-#define RECHECK_VAR_AVAILABLE_USEC (30*USEC_PER_SEC)
-
 #define N_IOVEC_META_FIELDS 17
 
 #define ENTRY_SIZE_MAX (1024*1024*32)
 #define N_IOVEC_META_FIELDS 17
 
 #define ENTRY_SIZE_MAX (1024*1024*32)
@@ -121,8 +119,6 @@ static const char* const storage_table[] = {
 DEFINE_STRING_TABLE_LOOKUP(storage, Storage);
 DEFINE_CONFIG_PARSE_ENUM(config_parse_storage, storage, Storage, "Failed to parse storage setting");
 
 DEFINE_STRING_TABLE_LOOKUP(storage, Storage);
 DEFINE_CONFIG_PARSE_ENUM(config_parse_storage, storage, Storage, "Failed to parse storage setting");
 
-static int server_flush_to_var(Server *s);
-
 static uint64_t available_space(Server *s) {
         char ids[33], *p;
         const char *f;
 static uint64_t available_space(Server *s) {
         char ids[33], *p;
         const char *f;
@@ -630,8 +626,6 @@ static void dispatch_message_real(
 
         assert(n <= m);
 
 
         assert(n <= m);
 
-        server_flush_to_var(s);
-
 retry:
         f = find_journal(s, realuid == 0 ? 0 : loginuid);
         if (f) {
 retry:
         f = find_journal(s, realuid == 0 ? 0 : loginuid);
         if (f) {
@@ -1963,8 +1957,8 @@ static int system_journal_open(Server *s) {
         sd_id128_to_string(machine, ids);
 
         if (!s->system_journal &&
         sd_id128_to_string(machine, ids);
 
         if (!s->system_journal &&
-            (s->storage == STORAGE_PERSISTENT ||
-             s->storage == STORAGE_AUTO)) {
+            (s->storage == STORAGE_PERSISTENT || s->storage == STORAGE_AUTO) &&
+            access("/run/systemd/journal/flushed", F_OK) >= 0) {
 
                 /* If in auto mode: first try to create the machine
                  * path, but not the prefix.
 
                 /* If in auto mode: first try to create the machine
                  * path, but not the prefix.
@@ -1972,7 +1966,7 @@ static int system_journal_open(Server *s) {
                  * If in persistent mode: create /var/log/journal and
                  * the machine path */
 
                  * If in persistent mode: create /var/log/journal and
                  * the machine path */
 
-                if (s->storage & STORAGE_PERSISTENT)
+                if (s->storage == STORAGE_PERSISTENT)
                         (void) mkdir("/var/log/journal/", 0755);
 
                 fn = strappend("/var/log/journal/", ids);
                         (void) mkdir("/var/log/journal/", 0755);
 
                 fn = strappend("/var/log/journal/", ids);
@@ -1982,7 +1976,6 @@ static int system_journal_open(Server *s) {
                 (void) mkdir(fn, 0755);
                 free(fn);
 
                 (void) mkdir(fn, 0755);
                 free(fn);
 
-                /* The create the system journal file */
                 fn = join("/var/log/journal/", ids, "/system.journal", NULL);
                 if (!fn)
                         return -ENOMEM;
                 fn = join("/var/log/journal/", ids, "/system.journal", NULL);
                 if (!fn)
                         return -ENOMEM;
@@ -2034,7 +2027,7 @@ static int system_journal_open(Server *s) {
                         /* OK, we really need the runtime journal, so create
                          * it if necessary. */
 
                         /* OK, we really need the runtime journal, so create
                          * it if necessary. */
 
-                        (void) mkdir_parents_label(fn, 0755);
+                        (void) mkdir_parents(fn, 0755);
                         r = journal_file_open_reliably(fn, O_RDWR|O_CREAT, 0640, NULL, &s->runtime_journal);
                         free(fn);
 
                         r = journal_file_open_reliably(fn, O_RDWR|O_CREAT, 0640, NULL, &s->runtime_journal);
                         free(fn);
 
@@ -2062,7 +2055,6 @@ static int server_flush_to_var(Server *s) {
         int r;
         sd_id128_t machine;
         sd_journal *j;
         int r;
         sd_id128_t machine;
         sd_journal *j;
-        usec_t ts;
 
         assert(s);
 
 
         assert(s);
 
@@ -2073,12 +2065,6 @@ static int server_flush_to_var(Server *s) {
         if (!s->runtime_journal)
                 return 0;
 
         if (!s->runtime_journal)
                 return 0;
 
-        ts = now(CLOCK_MONOTONIC);
-        if (s->var_available_timestamp + RECHECK_VAR_AVAILABLE_USEC > ts)
-                return 0;
-
-        s->var_available_timestamp = ts;
-
         system_journal_open(s);
 
         if (!s->system_journal)
         system_journal_open(s);
 
         if (!s->system_journal)
@@ -2215,6 +2201,7 @@ static int process_event(Server *s, struct epoll_event *ev) {
                 }
 
                 if (sfsi.ssi_signo == SIGUSR1) {
                 }
 
                 if (sfsi.ssi_signo == SIGUSR1) {
+                        touch("/run/systemd/journal/flushed");
                         server_flush_to_var(s);
                         return 1;
                 }
                         server_flush_to_var(s);
                         return 1;
                 }
index 544994da4dcbfebf97e8dc8dd9c64b1fcc196ec5..de5117914d298fb48a20eb7b2067b3fca2e83c9a 100644 (file)
@@ -1,3 +1,4 @@
+/systemd-journal-flush.service
 /systemd-hibernate.service
 /systemd-suspend.service
 /console-getty.service
 /systemd-hibernate.service
 /systemd-suspend.service
 /console-getty.service
diff --git a/units/systemd-journal-flush.service.in b/units/systemd-journal-flush.service.in
new file mode 100644 (file)
index 0000000..503e8a6
--- /dev/null
@@ -0,0 +1,18 @@
+#  This file is part of systemd.
+#
+#  systemd is free software; you can redistribute it and/or modify it
+#  under the terms of the GNU Lesser General Public License as published by
+#  the Free Software Foundation; either version 2.1 of the License, or
+#  (at your option) any later version.
+
+[Unit]
+Description=Trigger Flushing of Journal to Persistent Storage
+Documentation=man:systemd-journald.service(8) man:journald.conf(5)
+DefaultDependencies=no
+Requires=systemd-journald.service
+After=systemd-journald.service local-fs.target remote-fs.target
+Before=systemd-user-sessions.service
+
+[Service]
+ExecStart=@rootbindir@/systemctl kill --kill-who=main --signal=SIGUSR1 systemd-journald.service
+Type=oneshot
index 9552b454a341ccdfd45cb303e3a8e091e1ba0d71..3899745306c44de278f523ba29f141a161f8a118 100644 (file)
@@ -9,6 +9,7 @@
 Description=Journal Service
 Documentation=man:systemd-journald.service(8) man:journald.conf(5)
 DefaultDependencies=no
 Description=Journal Service
 Documentation=man:systemd-journald.service(8) man:journald.conf(5)
 DefaultDependencies=no
+Wants=systemd-journal-flush.service
 Requires=systemd-journald.socket
 After=systemd-journald.socket syslog.socket
 
 Requires=systemd-journald.socket
 After=systemd-journald.socket syslog.socket