mirror of
https://github.com/systemd/systemd.git
synced 2024-12-22 17:35:35 +03:00
journalctl: support -b all
to negate effect of -b
Also fix an issue where -b without argument didn't always behave as -b0
This commit is contained in:
parent
b5587fa994
commit
4890482531
@ -461,8 +461,8 @@
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>-b <optional><replaceable>ID</replaceable></optional><optional><replaceable>±offset</replaceable></optional></option></term>
|
||||
<term><option>--boot=<optional><replaceable>ID</replaceable></optional><optional><replaceable>±offset</replaceable></optional></option></term>
|
||||
<term><option>-b <optional><optional><replaceable>ID</replaceable></optional><optional><replaceable>±offset</replaceable></optional>|<constant>all</constant></optional></option></term>
|
||||
<term><option>--boot<optional>=<optional><replaceable>ID</replaceable></optional><optional><replaceable>±offset</replaceable></optional>|<constant>all</constant></optional></option></term>
|
||||
|
||||
<listitem><para>Show messages from a specific boot. This will
|
||||
add a match for <literal>_BOOT_ID=</literal>.</para>
|
||||
@ -494,6 +494,10 @@
|
||||
<replaceable>offset</replaceable> is not specified, a value of
|
||||
zero is assumed, and the logs for the boot given by
|
||||
<replaceable>ID</replaceable> are shown.</para>
|
||||
|
||||
<para>The special argument <constant>all</constant> can be
|
||||
used to negate the effect of an earlier use of
|
||||
<option>-b</option>.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user