dcavalca / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone
Pablo Greco 48fc63
From 5ccf02d71c36bed22929893f3ad5374a333daf77 Mon Sep 17 00:00:00 2001
Pablo Greco 48fc63
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
Pablo Greco 48fc63
Date: Tue, 28 Jun 2016 16:12:47 -0400
Pablo Greco 48fc63
Subject: [PATCH] journalct: allow --boot=0 to DTRT with --file/--directory
Pablo Greco 48fc63
Pablo Greco 48fc63
--boot=0 magically meant "this boot", but when used with --file/--directory it
Pablo Greco 48fc63
should simply refer to the last boot found in the specified journal. This way,
Pablo Greco 48fc63
--boot and --list-boots are consistent.
Pablo Greco 48fc63
Pablo Greco 48fc63
Fixes #3603.
Pablo Greco 48fc63
Pablo Greco 48fc63
(cherry picked from commit 592855c3189549fed93b1060b72299910c6ab1d0)
Pablo Greco 48fc63
Pablo Greco 48fc63
Related: #1463678
Pablo Greco 48fc63
---
Pablo Greco 48fc63
 src/journal/journalctl.c | 9 +++++++--
Pablo Greco 48fc63
 1 file changed, 7 insertions(+), 2 deletions(-)
Pablo Greco 48fc63
Pablo Greco 48fc63
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
Pablo Greco 48fc63
index b9549602d9..077dc37f76 100644
Pablo Greco 48fc63
--- a/src/journal/journalctl.c
Pablo Greco 48fc63
+++ b/src/journal/journalctl.c
Pablo Greco 48fc63
@@ -1050,7 +1050,7 @@ static int get_boots(
Pablo Greco 48fc63
         /* Adjust for the asymmetry that offset 0 is
Pablo Greco 48fc63
          * the last (and current) boot, while 1 is considered the
Pablo Greco 48fc63
          * (chronological) first boot in the journal. */
Pablo Greco 48fc63
-        skip_once = query_ref_boot && sd_id128_is_null(query_ref_boot->id) && ref_boot_offset < 0;
Pablo Greco 48fc63
+        skip_once = query_ref_boot && sd_id128_is_null(query_ref_boot->id) && ref_boot_offset <= 0;
Pablo Greco 48fc63
 
Pablo Greco 48fc63
         /* Advance to the earliest/latest occurrence of our reference
Pablo Greco 48fc63
          * boot ID (taking our lookup direction into account), so that
Pablo Greco 48fc63
@@ -1188,7 +1188,12 @@ static int add_boot(sd_journal *j) {
Pablo Greco 48fc63
         if (!arg_boot)
Pablo Greco 48fc63
                 return 0;
Pablo Greco 48fc63
 
Pablo Greco 48fc63
-        if (arg_boot_offset == 0 && sd_id128_equal(arg_boot_id, SD_ID128_NULL))
Pablo Greco 48fc63
+        /* Take a shortcut and use the current boot_id, which we can do very quickly.
Pablo Greco 48fc63
+         * We can do this only when we logs are coming from the current machine,
Pablo Greco 48fc63
+         * so take the slow path if log location is specified. */
Pablo Greco 48fc63
+        if (arg_boot_offset == 0 && sd_id128_equal(arg_boot_id, SD_ID128_NULL) &&
Pablo Greco 48fc63
+            !arg_directory && !arg_file)
Pablo Greco 48fc63
+
Pablo Greco 48fc63
                 return add_match_this_boot(j, arg_machine);
Pablo Greco 48fc63
 
Pablo Greco 48fc63
         ref_boot_id.id = arg_boot_id;