Skip to content
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

Merged
merged 11 commits into from May 10, 2024

Conversation

yuwata
Copy link
Member

@yuwata yuwata commented Apr 26, 2024

split-out of #32448.

@yuwata yuwata added the journal label Apr 26, 2024
@yuwata yuwata added this to the v256 milestone Apr 26, 2024
@github-actions github-actions bot added util-lib tests please-review PR is ready for (re-)review by a maintainer labels Apr 26, 2024
@yuwata yuwata force-pushed the journalctl-fix-boot branch 2 times, most recently from dbe7471 to cc869c3 Compare April 26, 2024 06:03
@yuwata yuwata changed the title journalctl: several fixes for --boot= option handling journalctl: several fixes and cleanups for --boot= option handling Apr 27, 2024
YHNdnzj added a commit to YHNdnzj/systemd that referenced this pull request Apr 29, 2024
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));
Copy link
Member

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?

Copy link
Member Author

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.

src/journal/journalctl-util.c Outdated Show resolved Hide resolved
src/journal/journalctl-misc.c Outdated Show resolved Hide resolved
@@ -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))
Copy link
Member

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.

Copy link
Member Author

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.

@bluca bluca added reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks and removed please-review PR is ready for (re-)review by a maintainer labels Apr 29, 2024
bluca pushed a commit that referenced this pull request Apr 29, 2024
@github-actions github-actions bot added please-review PR is ready for (re-)review by a maintainer and removed reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks labels Apr 30, 2024
src/journal/journalctl-util.c Outdated Show resolved Hide resolved
@bluca bluca added needs-rebase good-to-merge/with-minor-suggestions and removed please-review PR is ready for (re-)review by a maintainer labels May 3, 2024
It is always equivalent to getuid(). Let's call getuid() in the
function instead.
- 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.
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.
@yuwata yuwata added good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed and removed good-to-merge/with-minor-suggestions labels May 10, 2024
@bluca bluca merged commit cf2b044 into systemd:main May 10, 2024
43 of 48 checks passed
@github-actions github-actions bot removed the good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed label May 10, 2024
@yuwata yuwata deleted the journalctl-fix-boot branch May 10, 2024 11:45
Comment on lines +142 to +150
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;
Copy link
Member

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?

Copy link
Member Author

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.

BtbN pushed a commit to BtbN/systemd that referenced this pull request May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

3 participants