fix(cli): reset SIGPIPE to default so piping to head/tail exits quietly - #733
Open
platinummonkey wants to merge 1 commit into
Open
fix(cli): reset SIGPIPE to default so piping to head/tail exits quietly#733platinummonkey wants to merge 1 commit into
platinummonkey wants to merge 1 commit into
Conversation
…uietly Piping pup output into `head`/`tail` (e.g. `pup logs search --query='*' | head -n 20`) panicked with "failed printing to stdout: Broken pipe (os error 32)". Rust ignores SIGPIPE by default, so a closed pipe surfaces as an EPIPE error, which println!/print! turn into a panic instead of a clean exit. Reset SIGPIPE to SIG_DFL at process start, the standard fix used by ripgrep, fd, and other Unix CLI tools, so the process now exits quietly via the signal instead of panicking. - src/main.rs: add reset_sigpipe(), called at the top of main() - Cargo.toml/Cargo.lock: add libc as a unix-only target dependency Verified by building both the pre-fix and post-fix binaries and running `pup completions bash | head -n 1`: the old binary panicked (exit 101), the new binary exits cleanly via SIGPIPE (exit 141). cargo fmt --check and cargo clippy --all-targets -- -D warnings both pass, and the new reset_sigpipe_tests::sets_default_disposition unit test passes. Environment: Datadog workspace Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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
pupoutput intohead/tail(e.g.pup logs search --query='*' | head -n 20) panicked withfailed printing to stdout: Broken pipe (os error 32). Rust ignoresSIGPIPEby default, so a closed pipe surfaces as anEPIPEerror, whichprintln!/print!turn into a panic instead of a clean exit.SIGPIPEtoSIG_DFLat process start — the standard fix used byripgrep,fd, and other Unix CLI tools — so the process now exits quietly via the signal instead of panicking.Changes
src/main.rs: addreset_sigpipe(), called at the top ofmain()(native target), plus a unit test (reset_sigpipe_tests::sets_default_disposition)Cargo.toml/Cargo.lock: addlibcas acfg(unix)-only target dependency (already a transitive dependency at the pinned version, no new crate introduced)Testing
pup completions bash | head -n 1:thread 'main' panicked ... failed to write completion file: Broken pipe, exit code 101cargo test reset_sigpipepassescargo fmt --checkpassescargo clippy --all-targets -- -D warningspassesRelated Issues
Fixes the broken pipe panic reported when piping
pupoutput tohead.🤖 Generated with Claude Code