diff: exit 141 on a closed output pipe instead of panicking - #282
Open
MsfPablo wants to merge 1 commit into
Open
diff: exit 141 on a closed output pipe instead of panicking#282MsfPablo wants to merge 1 commit into
MsfPablo wants to merge 1 commit into
Conversation
diff writes the full result buffer (and side-by-side writes each line) with a bare .unwrap(), so a reader closing early (diff big1 big2 | head) turns a BrokenPipe error into a panic and a core dump (exit 134). GNU diff dies quietly to SIGPIPE (exit 141) in the same situation. Handle BrokenPipe explicitly at both write sites and exit(141); any other write error still panics since it would be a genuine bug. Fixes uutils#244
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
diff's output write is a bare.unwrap()(normal/context/unified/ed path insrc/diff.rs:94, side-by-side path insrc/side_diff.rs), so when the reader closes the pipe early (diff big1 big2 | head) theBrokenPipeerror is unwrapped and the process panics/aborts (exit 134) instead of dying quietly toSIGPIPElike GNU (exit 141).Fix
Added
exit_on_broken_pipe_or_panicinsrc/utils.rs: onErrorKind::BrokenPipeit exits with 141 (matching GNU); any other write error still panics, since that would be a genuine bug. Wired it into both write sites.Test plan
cargo build— cleancargo test— 21 passedcargo fmt -- --check/cargo clippy --all-targets— clean (pre-existing warnings in unrelated test code untouched)diff big1 big2 | head -1— before: panic, exit 134; after: exit 141diff -y big1 big2 | head -1Fixes #244
🤖 Generated with Claude Code