Skip to content

tar: restore SIGPIPE default so broken pipes exit 141 like GNU tar - #360

Open
MsfPablo wants to merge 1 commit into
uutils:mainfrom
MsfPablo:fix-brokenpipe-exit-code
Open

MsfPablo wants to merge 1 commit into
uutils:mainfrom
MsfPablo:fix-brokenpipe-exit-code

Conversation

@MsfPablo

Copy link
Copy Markdown

Fixes #263.

Problem

Rust's runtime ignores SIGPIPE by default, so when the reader of tar's stdout goes away (tar tf foo.tar | head -1), the resulting BrokenPipe error surfaced as a noisy TarError::Io on stderr with exit code 2. GNU tar dies silently via SIGPIPE with exit status 141.

Fix

Restore the default SIGPIPE disposition at startup (Unix only) so tar dies via SIGPIPE — exit status 141, no error output — matching GNU tar on all output paths (list, extract, create).

Testing

  • cargo test: 62 passed (incl. new test_list_broken_pipe_exits_via_sigpipe, which lists an archive larger than a pipe through a closed reader and asserts death by SIGPIPE)
  • Manual: tar -tf big.tar | head -1 now yields echo ${PIPESTATUS[0]} = 141 (was 2)

Assisted-by: Claude noreply@anthropic.com

Rust's runtime ignores SIGPIPE by default, so listing an archive through a
closed reader (e.g. `tar tf foo.tar | head -1`) surfaced a noisy
TarError::Io with exit code 2 instead of dying silently via SIGPIPE.

Restore the default SIGPIPE disposition at startup on Unix so every
output path (list, extract, create) matches GNU tar's exit status 141.

Fixes uutils#263

Assisted-by: Claude <noreply@anthropic.com>
@MsfPablo
MsfPablo requested a review from kaladron as a code owner September 12, 2026 20:40
@codspeed-hq

codspeed-hq Bot commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 7 untouched benchmarks


Comparing MsfPablo:fix-brokenpipe-exit-code (f6fca2b) with main (d51f497)

Open in CodSpeed

@codecov

codecov Bot commented Sep 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.80%. Comparing base (791ae26) to head (f6fca2b).
⚠️ Report is 54 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #360      +/-   ##
==========================================
+ Coverage   96.84%   97.80%   +0.95%     
==========================================
  Files          11       15       +4     
  Lines        1492     1779     +287     
  Branches       29       34       +5     
==========================================
+ Hits         1445     1740     +295     
+ Misses         46       38       -8     
  Partials        1        1              
Flag Coverage Δ
macos_latest 97.80% <100.00%> (+0.95%) ⬆️
ubuntu_latest 97.80% <100.00%> (+0.95%) ⬆️
windows_latest 0.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

TarError::Io returns exit code 2, GNU tar returns exit code 141

1 participant