-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
journalctl: several fixes and cleanups for --boot= option handling #32491
Changes from all commits
8ac0810
131701d
fdd325f
781ddf1
ae0e6de
87dfaba
a467515
afcd9c6
8f2bcb1
5da5d84
d0936a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,15 +104,21 @@ STATIC_DESTRUCTOR_REGISTER(arg_output_fields, set_freep); | |
STATIC_DESTRUCTOR_REGISTER(arg_compiled_pattern, pattern_freep); | ||
STATIC_DESTRUCTOR_REGISTER(arg_image_policy, image_policy_freep); | ||
|
||
static int parse_boot_descriptor(const char *x, sd_id128_t *boot_id, int *offset) { | ||
static int parse_id_descriptor(const char *x, sd_id128_t *ret_id, int *ret_offset) { | ||
sd_id128_t id = SD_ID128_NULL; | ||
int off = 0, r; | ||
|
||
assert(x); | ||
assert(ret_id); | ||
assert(ret_offset); | ||
|
||
if (streq(x, "all")) { | ||
*boot_id = SD_ID128_NULL; | ||
*offset = 0; | ||
*ret_id = SD_ID128_NULL; | ||
*ret_offset = 0; | ||
return 0; | ||
} else if (strlen(x) >= SD_ID128_STRING_MAX - 1) { | ||
} | ||
|
||
if (strlen(x) >= SD_ID128_STRING_MAX - 1) { | ||
char *t; | ||
|
||
t = strndupa_safe(x, SD_ID128_STRING_MAX - 1); | ||
|
@@ -134,12 +140,8 @@ static int parse_boot_descriptor(const char *x, sd_id128_t *boot_id, int *offset | |
return r; | ||
} | ||
|
||
if (boot_id) | ||
*boot_id = id; | ||
|
||
if (offset) | ||
*offset = off; | ||
|
||
*ret_id = id; | ||
*ret_offset = off; | ||
return 1; | ||
} | ||
|
||
|
@@ -517,19 +519,16 @@ static int parse_argv(int argc, char *argv[]) { | |
arg_boot_offset = 0; | ||
|
||
if (optarg) { | ||
r = parse_boot_descriptor(optarg, &arg_boot_id, &arg_boot_offset); | ||
r = parse_id_descriptor(optarg, &arg_boot_id, &arg_boot_offset); | ||
if (r < 0) | ||
return log_error_errno(r, "Failed to parse boot descriptor '%s'", optarg); | ||
|
||
arg_boot = r; | ||
|
||
/* 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); | ||
/* 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... */ | ||
r = parse_id_descriptor(argv[optind], &arg_boot_id, &arg_boot_offset); | ||
if (r >= 0) { | ||
arg_boot = r; | ||
optind++; | ||
|
@@ -958,7 +957,7 @@ static int parse_argv(int argc, char *argv[]) { | |
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), | ||
"Please specify either --reverse or --follow, not both."); | ||
|
||
if (arg_lines >= 0 && arg_lines_oldest && (arg_reverse || arg_follow)) | ||
if (arg_action == ACTION_SHOW && arg_lines >= 0 && arg_lines_oldest && (arg_reverse || arg_follow)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I think asking for the first N lines and then reverse that is really a niche use case, that I don't want to support. Let's leave this out for now I'd say, so that this is less confusing for different verbs. We can always revisit this if people really want it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before the commit,
I do not think it is niche. Even if it is, there is no reason to refuse the combination. Both behavior and implementation is super simple to understand. Personally, I'd like to also support the combination even when showing journal entries, even if it is niche. But, that's not simple to implement, and I'd like to leave that to a later PR. |
||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), | ||
"--lines=+N is unsupported when --reverse or --follow is specified."); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, is the comment correct? I think the index is sorted in ascending order, hence older IDs are always shown earlier?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. The last commit adds additional argument for journal_get_boots() that controls the ordering.