]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journalctl: do not override explicitly specified -b or -n with -e or -k
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 20 Nov 2024 10:28:20 +0000 (19:28 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 11 Dec 2024 09:12:13 +0000 (18:12 +0900)
Fixes #35248.

man/journalctl.xml
src/journal/journalctl-util.c
src/journal/journalctl.c
src/journal/journalctl.h

index 0cc2b72acc5149a5f7b9034ffb47565936df8715..7d8f159fbf9bd7bb49d016ac88f0a6bf686e6e94 100644 (file)
         <term><option>-k</option></term>
         <term><option>--dmesg</option></term>
 
-        <listitem><para>Show only kernel messages. This implies <option>-b</option> and adds the match
-        <literal>_TRANSPORT=kernel</literal>.</para>
+        <listitem><para>Show only kernel messages. This adds the match <literal>_TRANSPORT=kernel</literal>.
+        This implies <option>--boot=0</option> unless explicitly specified otherwise.</para>
 
         <xi:include href="version-info.xml" xpointer="v205"/></listitem>
       </varlistentry>
         <term><option>--pager-end</option></term>
 
         <listitem><para>Immediately jump to the end of the journal inside the implied pager tool. This
-        implies <option>-n1000</option> to guarantee that the pager will not buffer logs of unbounded
-        size. This may be overridden with an explicit <option>-n</option> with some other numeric value,
-        while <option>-nall</option> will disable this cap.  Note that this option is only supported for
-        the <citerefentry
-        project='man-pages'><refentrytitle>less</refentrytitle><manvolnum>1</manvolnum></citerefentry>
+        implies <option>--lines=1000</option> and <option>--boot=0</option> unless explicitly specified
+        otherwise, to guarantee that the pager will not buffer logs of unbounded size. Note that this option
+        is only supported for the
+        <citerefentry project='man-pages'><refentrytitle>less</refentrytitle><manvolnum>1</manvolnum></citerefentry>
         pager.</para>
 
         <xi:include href="version-info.xml" xpointer="v198"/></listitem>
index 1996bddf605856e67688168d169141969bddf15b..1e663b0c8ce5101d08b5a00707485078d2f2df77 100644 (file)
@@ -74,12 +74,8 @@ int journal_acquire_boot(sd_journal *j) {
 
         assert(j);
 
-        if (!arg_boot) {
-                /* Clear relevant field for safety. */
-                arg_boot_id = SD_ID128_NULL;
-                arg_boot_offset = 0;
+        if (!arg_boot)
                 return 0;
-        }
 
         /* Take a shortcut and use the current boot_id, which we can do very quickly.
          * We can do this only when the logs are coming from the current machine,
index 084e1b492d3c00c1a878a7014a1abb068ac36c33..37cda775542582286bef792ed18873b53071da9e 100644 (file)
@@ -45,7 +45,7 @@ bool arg_no_tail = false;
 bool arg_truncate_newline = false;
 bool arg_quiet = false;
 bool arg_merge = false;
-bool arg_boot = false;
+int arg_boot = -1; /* tristate */
 sd_id128_t arg_boot_id = {};
 int arg_boot_offset = 0;
 bool arg_dmesg = false;
@@ -452,12 +452,6 @@ static int parse_argv(int argc, char *argv[]) {
 
                 case 'e':
                         arg_pager_flags |= PAGER_JUMP_TO_END;
-
-                        if (arg_lines == ARG_LINES_DEFAULT)
-                                arg_lines = 1000;
-
-                        arg_boot = true;
-
                         break;
 
                 case 'f':
@@ -563,7 +557,7 @@ static int parse_argv(int argc, char *argv[]) {
                         break;
 
                 case 'k':
-                        arg_boot = arg_dmesg = true;
+                        arg_dmesg = true;
                         break;
 
                 case ARG_SYSTEM:
@@ -987,11 +981,19 @@ static int parse_argv(int argc, char *argv[]) {
         if (arg_no_tail)
                 arg_lines = ARG_LINES_ALL;
 
-        if (arg_follow && !arg_since_set && arg_lines == ARG_LINES_DEFAULT)
-                arg_lines = 10;
+        if (arg_lines == ARG_LINES_DEFAULT) {
+                if (arg_follow && !arg_since_set)
+                        arg_lines = 10;
+                else if (FLAGS_SET(arg_pager_flags, PAGER_JUMP_TO_END))
+                        arg_lines = 1000;
+        }
 
-        if (arg_follow && !arg_merge && !arg_boot) {
-                arg_boot = true;
+        if (arg_boot < 0)
+                /* Show the current boot if -f/--follow, -k/--dmesg, or -e/--pager-end is specified unless
+                 * -m/--merge is specified. */
+                arg_boot = !arg_merge && (arg_follow || arg_dmesg || FLAGS_SET(arg_pager_flags, PAGER_JUMP_TO_END));
+        if (!arg_boot) {
+                /* Clear the boot ID and offset if -b/--boot is unspecified for safety. */
                 arg_boot_id = SD_ID128_NULL;
                 arg_boot_offset = 0;
         }
index 5e3e73544fbf77acbd8f57ae3988cc7d51c2d831..9db66897598c68e1f25a70480a1d636d70f05377 100644 (file)
@@ -50,7 +50,7 @@ extern bool arg_no_tail;
 extern bool arg_truncate_newline;
 extern bool arg_quiet;
 extern bool arg_merge;
-extern bool arg_boot;
+extern int arg_boot;
 extern sd_id128_t arg_boot_id;
 extern int arg_boot_offset;
 extern bool arg_dmesg;