From: dana Date: Thu, 7 Mar 2019 01:20:06 +0000 (-0600) Subject: journalctl: support `-b all` to negate effect of -b X-Git-Tag: v242-rc1~111 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4890482531a4c36d0f0fa37a3734fd809d95f305;p=thirdparty%2Fsystemd.git journalctl: support `-b all` to negate effect of -b Also fix an issue where -b without argument didn't always behave as -b0 --- diff --git a/man/journalctl.xml b/man/journalctl.xml index 1ea7b24df13..a3c67f5e82d 100644 --- a/man/journalctl.xml +++ b/man/journalctl.xml @@ -461,8 +461,8 @@ - - + + Show messages from a specific boot. This will add a match for _BOOT_ID=. @@ -494,6 +494,10 @@ offset is not specified, a value of zero is assumed, and the logs for the boot given by ID are shown. + + The special argument all can be + used to negate the effect of an earlier use of + . diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 42a5a09608f..f2386762b22 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -266,7 +266,11 @@ static int parse_boot_descriptor(const char *x, sd_id128_t *boot_id, int *offset sd_id128_t id = SD_ID128_NULL; int off = 0, r; - if (strlen(x) >= 32) { + if (streq(x, "all")) { + *boot_id = SD_ID128_NULL; + *offset = 0; + return 0; + } else if (strlen(x) >= 32) { char *t; t = strndupa(x, 32); @@ -294,7 +298,7 @@ static int parse_boot_descriptor(const char *x, sd_id128_t *boot_id, int *offset if (offset) *offset = off; - return 0; + return 1; } static int help(void) { @@ -593,30 +597,34 @@ static int parse_argv(int argc, char *argv[]) { case ARG_THIS_BOOT: arg_boot = true; + arg_boot_id = SD_ID128_NULL; + arg_boot_offset = 0; break; case 'b': arg_boot = true; + arg_boot_id = SD_ID128_NULL; + arg_boot_offset = 0; if (optarg) { r = parse_boot_descriptor(optarg, &arg_boot_id, &arg_boot_offset); - if (r < 0) { - log_error("Failed to parse boot descriptor '%s'", optarg); - return -EINVAL; - } - } else { + if (r < 0) + return log_error_errno(r, "Failed to parse boot descriptor '%s'", optarg); - /* Hmm, no argument? Maybe the next - * word on the command line is - * supposed to be the argument? Let's - * see if there is one and is parsable - * as a boot descriptor... */ + arg_boot = r; - if (optind < argc && - parse_boot_descriptor(argv[optind], &arg_boot_id, &arg_boot_offset) >= 0) + /* Hmm, no argument? Maybe the next + * word on the command line is + * supposed to be the argument? Let's + * see if there is one and is parsable + * as a boot descriptor... */ + } else if (optind < argc) { + r = parse_boot_descriptor(argv[optind], &arg_boot_id, &arg_boot_offset); + if (r >= 0) { + arg_boot = r; optind++; + } } - break; case ARG_LIST_BOOTS: diff --git a/test/TEST-04-JOURNAL/test-journal.sh b/test/TEST-04-JOURNAL/test-journal.sh index 260cae09ab1..e198cb6ede0 100755 --- a/test/TEST-04-JOURNAL/test-journal.sh +++ b/test/TEST-04-JOURNAL/test-journal.sh @@ -63,6 +63,18 @@ grep -q '^PRIORITY=6$' /output ! grep -q '^FOO=' /output ! grep -q '^SYSLOG_FACILITY=' /output +# `-b all` negates earlier use of -b (-b and -m are otherwise exclusive) +journalctl -b -1 -b all -m > /dev/null + +# -b always behaves like -b0 +journalctl -q -b-1 -b0 | head -1 > /expected +journalctl -q -b-1 -b | head -1 > /output +cmp /expected /output +# ... even when another option follows (both of these should fail due to -m) +{ journalctl -ball -b0 -m 2>&1 || :; } | head -1 > /expected +{ journalctl -ball -b -m 2>&1 || :; } | head -1 > /output +cmp /expected /output + # Don't lose streams on restart systemctl start forever-print-hola sleep 3