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

logging: fix connected_to_journal logic #119

Merged
merged 1 commit into from
Oct 20, 2022
Merged

Conversation

lucab
Copy link
Owner

@lucab lucab commented Oct 20, 2022

This tweaks the conditional checks in connected_to_journal() logic, in order to avoid buggy cases.
In particular, in case of errors we may have ended up comparing None values possibly coming from the two sides (env and stdout/stderr stat), thus returning a false positive to consumers.
Let's instead change the logic to be more explicit in case of real positive results, and use a single fallback for all negative cases.

@lucab lucab requested a review from swsnr October 20, 2022 08:07
@lucab
Copy link
Owner Author

lucab commented Oct 20, 2022

/cc @lunaryorn for review

I was re-reading this code for unrelated reasons, and I think I spotted a logic bug due to the use of .ok() transformers. Please double-check my current reading of it.

src/logging.rs Outdated Show resolved Hide resolved
@lucab lucab force-pushed the ups/fix-journal-connect-check branch from d4346c6 to 8e4cd2f Compare October 20, 2022 13:54
swsnr
swsnr previously approved these changes Oct 20, 2022
Copy link
Collaborator

@swsnr swsnr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this mistake 😌

src/logging.rs Outdated
|| stream == JournalStream::from_fd(std::io::stdout()).ok()
JournalStream::from_env_default().map_or(false, |env_stream| {
JournalStream::from_fd(io::stderr()).map_or(false, |o| o == env_stream)
|| JournalStream::from_fd(io::stdout()).map_or(false, |e| e == env_stream)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was about to say that this is .exists only to realize that this doesn't exist in Rust 😅

LGTM

This tweaks the conditional checks in `connected_to_journal()` logic,
in order to avoid buggy cases.
In particular, in case of errors we may have ended up comparing `None`
values possibly coming from the two sides (env and stdout/stderr stat),
thus returning a false positive to consumers.
Let's instead change the logic to be more explicit in case of real
positive results, and use a single fallback for all negative cases.
@lucab lucab force-pushed the ups/fix-journal-connect-check branch from 8e4cd2f to ec81ae6 Compare October 20, 2022 15:12
@lucab lucab merged commit bc50aba into master Oct 20, 2022
@lucab lucab deleted the ups/fix-journal-connect-check branch October 20, 2022 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants