]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journalct: allow --boot=0 to DTRT with --file/--directory 3622/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 28 Jun 2016 20:12:47 +0000 (16:12 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 28 Jun 2016 20:19:59 +0000 (16:19 -0400)
--boot=0 magically meant "this boot", but when used with --file/--directory it
should simply refer to the last boot found in the specified journal. This way,
--boot and --list-boots are consistent.

Fixes #3603.

src/journal/journalctl.c

index 8c59bacc0bc00159607a797c79754b3eba7ada18..4cc0c2b6c2cb71a9a7b245d2b3315794be7202f8 100644 (file)
@@ -1121,7 +1121,7 @@ static int get_boots(
         /* Adjust for the asymmetry that offset 0 is
          * the last (and current) boot, while 1 is considered the
          * (chronological) first boot in the journal. */
-        skip_once = boot_id && sd_id128_is_null(*boot_id) && offset < 0;
+        skip_once = boot_id && sd_id128_is_null(*boot_id) && offset <= 0;
 
         /* Advance to the earliest/latest occurrence of our reference
          * boot ID (taking our lookup direction into account), so that
@@ -1263,7 +1263,12 @@ static int add_boot(sd_journal *j) {
         if (!arg_boot)
                 return 0;
 
-        if (arg_boot_offset == 0 && sd_id128_equal(arg_boot_id, SD_ID128_NULL))
+        /* Take a shortcut and use the current boot_id, which we can do very quickly.
+         * We can do this only when we logs are coming from the current machine,
+         * so take the slow path if log location is specified. */
+        if (arg_boot_offset == 0 && sd_id128_equal(arg_boot_id, SD_ID128_NULL) &&
+            !arg_directory && !arg_file)
+
                 return add_match_this_boot(j, arg_machine);
 
         boot_id = arg_boot_id;