From: Yu Watanabe Date: Wed, 20 Nov 2024 10:28:20 +0000 (+0900) Subject: journalctl: do not override explicitly specified -b or -n with -e or -k X-Git-Tag: v258-rc1~1920 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f8bfe16b06ad3250cb9b41ba97aaa0a3613a588c;p=thirdparty%2Fsystemd.git journalctl: do not override explicitly specified -b or -n with -e or -k Fixes #35248. --- diff --git a/man/journalctl.xml b/man/journalctl.xml index 0cc2b72acc5..7d8f159fbf9 100644 --- a/man/journalctl.xml +++ b/man/journalctl.xml @@ -474,8 +474,8 @@ - Show only kernel messages. This implies and adds the match - _TRANSPORT=kernel. + Show only kernel messages. This adds the match _TRANSPORT=kernel. + This implies unless explicitly specified otherwise. @@ -809,11 +809,10 @@ Immediately jump to the end of the journal inside the implied pager tool. This - implies to guarantee that the pager will not buffer logs of unbounded - size. This may be overridden with an explicit with some other numeric value, - while will disable this cap. Note that this option is only supported for - the less1 + implies and 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 + less1 pager. diff --git a/src/journal/journalctl-util.c b/src/journal/journalctl-util.c index 1996bddf605..1e663b0c8ce 100644 --- a/src/journal/journalctl-util.c +++ b/src/journal/journalctl-util.c @@ -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, diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 084e1b492d3..37cda775542 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -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; } diff --git a/src/journal/journalctl.h b/src/journal/journalctl.h index 5e3e73544fb..9db66897598 100644 --- a/src/journal/journalctl.h +++ b/src/journal/journalctl.h @@ -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;