chiark / gitweb /
journalctl: add a marker to log output for reboots
authorLennart Poettering <lennart@poettering.net>
Tue, 10 Jul 2012 23:36:55 +0000 (01:36 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 10 Jul 2012 23:36:55 +0000 (01:36 +0200)
With this we'll print a marker "----- Reboot -----" between two
subsequent lines with different boot IDs.

TODO
man/journalctl.xml
src/journal/journalctl.c
src/journal/sd-journal.c

diff --git a/TODO b/TODO
index 5df72cdc5e1fa8af909fe613f52a2a0454f0aec3..0b646eaa2c481416d2ef7933a2e58d1c18efb3f3 100644 (file)
--- 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
index ffe988a6190b810360461b0977711eefd8fe2c5f..bb964b01ed5e1a860c45bcb0fc2bb89ce6fa179d 100644 (file)
 
                                 <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>
index 4c975d3e7c49c3b6c1bcea5df70918f1e86b23c5..43cd2a3feff46b3ff9ca88df5756eb91f665f799 100644 (file)
@@ -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);
index 6331f042cef865d65b58cd91283fa10e4692792f..5420be13ea0a6acbe95ac20f668f8550713caa7f 100644 (file)
@@ -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;
 }