naccyde / rpms / systemd

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