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
Conversation
dbe7471
to
cc869c3
Compare
cc869c3
to
c705b5f
Compare
options Prompted by systemd#32491
src/journal/journalctl-util.c
Outdated
r = journal_find_boot_by_id(j, arg_boot_id); | ||
if (r < 0) | ||
return log_error_errno(r, "Failed to find journal entry from the specified boot ID (%s): %m", | ||
SD_ID128_TO_STRING(arg_boot_id)); |
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.
switch to SD_ID128_FORMAT_STR
+ SD_ID128_FORMAT_VAL
while at it?
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.
Personally, I prefer '%s' + SD_ID128_TO_STRING()
. Here is not a performance critical path, so there should be no difference.
@@ -957,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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Before the commit, arg_lines
is only used when showing journal entries. Using the option in --list-boots is completely new here. And when showing list of boot IDs, the semantics is completely simple, and --lines=
and --reverse
can be and should be completely independent. If we keep the condition, even when showing list of boots, the options needlessly and spuriously interfere each other.
I think asking for the first N lines and then reverse that is really a niche use case
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.
c705b5f
to
7acfa10
Compare
It is always equivalent to getuid(). Let's call getuid() in the function instead.
Follow-up for 8e976dc.
- rename to parse_id_descriptor(), to make it usable for other kind of ID later. - add missing assertions, - prefix arguments for storing results with 'ret_', - drop unnecessary 'else'.
No functional change, just refactoring and prepration for later changes.
Follow-up for 592855c.
Otherwise, if several matches already set, then the first seek to head or tail may move the cursor to an invalid place, hence they provide wrong ID(s). Also, reading journal after calling these function may provide unexpected data. Currently, the caller does not install any matches before calling the functions, and does not read any journal entry after journal_get_boots() succeeds or journal_find_boot_by_offset() succeeds with 0. Hence, this should not change any behavior. Just for safety.
Fixes a regression introduced by e44f060. After the offending commit, if a boot ID suffixed with an offset is specified to --boot=, the boot ID was ignored. This fixes the issue. To fix the issue, this merges journal_find_boot_by_id() and journal_find_boot_by_offset().
Currently, the parsed timestamp is only used when advance_older is false. Hence, this does not change any behavior. But, let's fix it anyway.
No boot ID in journal should be definitly spurious. Let's warn about that and exit with failure.
Also mention that -r/--reverse is supported by the command.
7acfa10
to
d0936a7
Compare
if (arg_lines_needs_seek_end()) | ||
/* With --lines=N, we only know the negative index, and the older ID is located earlier. */ | ||
index = -i; | ||
else if (arg_lines >= 0) | ||
/* With --lines=+N, we only know the positive index, and the newer ID is located earlier. */ | ||
index = i + 1; | ||
else | ||
/* Otherwise, show negative index. Note, in this case, newer ID is located earlier. */ | ||
index = i + 1 - (int) n_boots; |
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.
options Prompted by systemd#32491 (cherry picked from commit 821bf13)
split-out of #32448.