Skip to content

wc: stop processing --files0-from input after stdout write failure#11023

Merged
cakebaker merged 2 commits intouutils:mainfrom
mattsu2020:wc_11009
Feb 19, 2026
Merged

wc: stop processing --files0-from input after stdout write failure#11023
cakebaker merged 2 commits intouutils:mainfrom
mattsu2020:wc_11009

Conversation

@mattsu2020
Copy link
Contributor

Summary

Fix wc --files0-from=- so it stops processing additional inputs after a stdout write failure.

With an unbounded --files0-from stream (e.g. yes /dev/null | tr '\n' '\0') and a failing stdout write, wc kept iterating and repeatedly printed:

wc: failed to print result for /dev/null: No space left on device

This could lead to the process not exiting as expected.

Fixes #11009.

Root cause

In the per-input loop, print_stats(...) errors were reported but not treated as a terminal condition.
As a result, wc continued consuming more paths from --files0-from=- even after stdout was no longer writable.

Changes

  • src/uu/wc/src/wc.rs

    • After reporting wc-error-failed-to-print-result, return from wc(...) immediately.
    • This prevents repeated write-error spam and allows the process to terminate.
  • tests/by-util/test_wc.rs

    • Add Linux-only regression test:
      • test_files0_stops_after_stdout_write_error
    • The test writes stdout to /dev/full and verifies that:
      • failed to print result for /dev/null is emitted only once.

When wc encounters a write error to stdout (e.g., when stdout is redirected to /dev/full), it should stop processing immediately rather than continuing to process remaining files. This matches GNU wc behavior and prevents unnecessary processing after the output is already broken.
@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/tty/tty-eof (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/basenc/bounded-memory is now being skipped but was previously passing.
Note: The gnu test tests/expand/bounded-memory is now being skipped but was previously passing.

@cakebaker cakebaker merged commit 2b10153 into uutils:main Feb 19, 2026
156 of 158 checks passed
@cakebaker
Copy link
Contributor

Thanks!

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.

wc:/dev/null No space left on device

2 participants