[systemd-commits] 3 commits - Makefile.am TODO man/journalctl.xml src/journal units/.gitignore units/systemd-journal-flush.service.in units/systemd-journald.service.in

Lennart Poettering lennart at kemper.freedesktop.org
Tue Jul 10 17:45:16 PDT 2012


 Makefile.am                            |    4 +++-
 TODO                                   |    8 --------
 man/journalctl.xml                     |    2 +-
 src/journal/journalctl.c               |   14 ++++++++++++++
 src/journal/journald.c                 |   23 +++++------------------
 src/journal/sd-journal.c               |    6 +++---
 units/.gitignore                       |    1 +
 units/systemd-journal-flush.service.in |   18 ++++++++++++++++++
 units/systemd-journald.service.in      |    1 +
 9 files changed, 46 insertions(+), 31 deletions(-)

New commits:
commit d957be9bae1f568b239dc6bd6c8af32a3b54bce6
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Jul 11 02:45:00 2012 +0200

    update TODO

diff --git a/TODO b/TODO
index 0b646ea..c4f21a3 100644
--- a/TODO
+++ b/TODO
@@ -69,17 +69,11 @@ Features:
 
 * nspawn: bind mount /var/log/journal from the host
 
-* The current Storage=auto logic is borked, since people cannot mount
-  /var/log/journal via NFS since the mount point has to exist and we
-  already take that as signal to store our stuff there.
-
 * Document:
         - PID 1 D-Bus API
         - Journal C API manual pages
         - scheduled shutdown API
 
-* wiki: document logind's PreparingForShutdown, PreparingForSleep
-
 * introduce Type=pid-file
 
 * systemctl list-unit-files appears to be broken for symlinked units in /usr/lib

commit b8156be03f71c53072c7126bb418410acbef6c81
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Jul 11 02:41:16 2012 +0200

    journal: replace implicit flushing of journal by explicit one
    
    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.

diff --git a/Makefile.am b/Makefile.am
index 70b8b09..6b10f60 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2331,7 +2331,8 @@ dist_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
@@ -2357,6 +2358,7 @@ EXTRA_DIST += \
 	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 += \
diff --git a/src/journal/journald.c b/src/journal/journald.c
index da9f528..2402f7f 100644
--- a/src/journal/journald.c
+++ b/src/journal/journald.c
@@ -69,8 +69,6 @@
 
 #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)
@@ -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");
 
-static int server_flush_to_var(Server *s);
-
 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);
 
-        server_flush_to_var(s);
-
 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 &&
-            (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.
@@ -1972,7 +1966,7 @@ static int system_journal_open(Server *s) {
                  * 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);
@@ -1982,7 +1976,6 @@ static int system_journal_open(Server *s) {
                 (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;
@@ -2034,7 +2027,7 @@ static int system_journal_open(Server *s) {
                         /* 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);
 
@@ -2062,7 +2055,6 @@ static int server_flush_to_var(Server *s) {
         int r;
         sd_id128_t machine;
         sd_journal *j;
-        usec_t ts;
 
         assert(s);
 
@@ -2073,12 +2065,6 @@ static int server_flush_to_var(Server *s) {
         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)
@@ -2215,6 +2201,7 @@ static int process_event(Server *s, struct epoll_event *ev) {
                 }
 
                 if (sfsi.ssi_signo == SIGUSR1) {
+                        touch("/run/systemd/journal/flushed");
                         server_flush_to_var(s);
                         return 1;
                 }
diff --git a/units/.gitignore b/units/.gitignore
index 544994d..de51179 100644
--- a/units/.gitignore
+++ b/units/.gitignore
@@ -1,3 +1,4 @@
+/systemd-journal-flush.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
index 0000000..503e8a6
--- /dev/null
+++ b/units/systemd-journal-flush.service.in
@@ -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
diff --git a/units/systemd-journald.service.in b/units/systemd-journald.service.in
index 9552b45..3899745 100644
--- a/units/systemd-journald.service.in
+++ b/units/systemd-journald.service.in
@@ -9,6 +9,7 @@
 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
 

commit 14a65d65a0c25ba4809b8d97f54ebf3e12eac84c
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Jul 11 01:36:55 2012 +0200

    journalctl: add a marker to log output for reboots
    
    With this we'll print a marker "----- Reboot -----" between two
    subsequent lines with different boot IDs.

diff --git a/TODO b/TODO
index 5df72cd..0b646ea 100644
--- a/TODO
+++ b/TODO
@@ -56,8 +56,6 @@ Features:
 
 * when running as user instance: implicitly default to WorkingDirectory=$HOME for all services.
 
-* journalctl highlight reboots
-
 * Merge KillUnit()'s mode and who params into one
 
 * load-fragment: when loading a unit file via a chain of symlinks
diff --git a/man/journalctl.xml b/man/journalctl.xml
index ffe988a..bb964b0 100644
--- a/man/journalctl.xml
+++ b/man/journalctl.xml
@@ -223,7 +223,7 @@
 
                                 <listitem><para>Takes an absolute
                                 directory path as argument. If
-                                specified will opearte on the
+                                specified will operate on the
                                 specified journal directory instead of
                                 the default runtime and system journal
                                 paths.</para></listitem>
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index 4c975d3..43cd2a3 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -299,6 +299,8 @@ int main(int argc, char *argv[]) {
         sd_journal *j = NULL;
         unsigned line = 0;
         bool need_seek = false;
+        sd_id128_t previous_boot_id;
+        bool previous_boot_id_valid = false;
 
         log_parse_environment();
         log_open();
@@ -390,6 +392,8 @@ int main(int argc, char *argv[]) {
 
         for (;;) {
                 for (;;) {
+                        sd_id128_t boot_id;
+
                         if (need_seek) {
                                 r = sd_journal_next(j);
                                 if (r < 0) {
@@ -401,6 +405,16 @@ int main(int argc, char *argv[]) {
                         if (r == 0)
                                 break;
 
+                        r = sd_journal_get_monotonic_usec(j, NULL, &boot_id);
+                        if (r >= 0) {
+                                if (previous_boot_id_valid &&
+                                    !sd_id128_equal(boot_id, previous_boot_id))
+                                        printf(ANSI_HIGHLIGHT_ON "----- Reboot -----" ANSI_HIGHLIGHT_OFF "\n");
+
+                                previous_boot_id = boot_id;
+                                previous_boot_id_valid = true;
+                        }
+
                         line ++;
 
                         r = output_journal(j, arg_output, line, 0, arg_show_all);
diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
index 6331f04..5420be1 100644
--- a/src/journal/sd-journal.c
+++ b/src/journal/sd-journal.c
@@ -1397,8 +1397,6 @@ _public_ int sd_journal_get_monotonic_usec(sd_journal *j, uint64_t *ret, sd_id12
 
         if (!j)
                 return -EINVAL;
-        if (!ret)
-                return -EINVAL;
 
         f = j->current_file;
         if (!f)
@@ -1422,7 +1420,9 @@ _public_ int sd_journal_get_monotonic_usec(sd_journal *j, uint64_t *ret, sd_id12
                         return -ESTALE;
         }
 
-        *ret = le64toh(o->entry.monotonic);
+        if (ret)
+                *ret = le64toh(o->entry.monotonic);
+
         return 0;
 }
 



More information about the systemd-commits mailing list