diff options
author | Lennart Poettering <lennart@poettering.net> | 2012-07-11 01:36:55 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2012-07-11 01:36:55 +0200 |
commit | 14a65d65a0c25ba4809b8d97f54ebf3e12eac84c (patch) | |
tree | 229e4739f87ef83f7f06a32ac16d26bf171c0213 /src | |
parent | a963990ff4ebc7908d3cf82bbd8cf34a42d57b7f (diff) |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/journal/journalctl.c | 14 | ||||
-rw-r--r-- | src/journal/sd-journal.c | 6 |
2 files changed, 17 insertions, 3 deletions
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 4c975d3e7c..43cd2a3fef 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 6331f042ce..5420be13ea 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; } |