Repository navigation
cat: report bad file descriptor when stdin is closed - #15253
ozenyunus35 wants to merge 2 commits into
Conversation
Rust reopens a closed stdin as /dev/null before uumain runs, so `cat <&-` read nothing and exited 0. Check whether stdin was closed at startup, as tac does, and fail with EBADF like reading fd 0 would.
|
@ozenyunus35 Please open an issue to track this work, then include |
|
GNU testsuite comparison: |
|
|
||
| #[test] | ||
| #[cfg(unix)] | ||
| #[cfg_attr(wasi_runner, ignore = "WASI: no subprocess spawning")] |
There was a problem hiding this comment.
wasi isn't unix, so this ignore is dead code under #[cfg(unix)], no?
There was a problem hiding this comment.
I seem to remember this being complicated, wasi_runner runs on a Unix host?
cc: @oech3
There was a problem hiding this comment.
Unfortunately, we need to exculude wasi_runner manually since host of test code is still Linux.
But I think we can use #[cfg(not(wasi_runner))] instead of ignore if EBADF is essentially unix specific.
| #[test] | ||
| #[cfg(unix)] | ||
| #[cfg_attr(wasi_runner, ignore = "WASI: no subprocess spawning")] | ||
| fn test_closed_stdin_with_file() { |
There was a problem hiding this comment.
this one already covers the previous test, could we keep only this one?
|
@sylvestre merged the two tests into one and switched to |
|
@ozenyunus35 please rebase for a clean commit history. the PR description could also be more concise. |
Merging this PR will degrade performance by 45.81%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Simulation | three_39_bit_primes |
490.4 ms | 1,722.7 ms | -71.53% |
| ⚡ | Simulation | five_38_bit_primes |
1.7 s | 1.6 s | +3.17% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing ozenyunus35:fix/cat-closed-stdin (03b6771) with main (efca981)2
Footnotes
-
54 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
-
No successful run was found on
main(d43f2b8) during the generation of this report, so efca981 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩
Closes #15278
Summary
Refs #14705 (
misc/close-stdin.sh).When
catis started with stdin closed, it currently treats the input as empty and exits successfully instead of reporting a bad file descriptor.This happens because Rust's runtime can reopen a closed stdin as
/dev/nullbefore the utility starts.Changes
uucore::signals::stdin_was_closed()check to detect closed stdin.EBADFwhencatattempts to read from a closed stdin.Testing
The new regression tests fail before the fix and pass afterward.
Validation completed:
cattests passed.cargo fmt --checkpassed.cargo clippy -p uu_cat --all-targets -D warningspassed./dev/nullinput continue to work correctly.The regression tests are skipped on WASI, where subprocess spawning is unavailable.
Scope
This change addresses the closed-stdin behavior of
catonly. Other utilities covered by the GNU compatibility test remain to be addressed separately.AI Assistance
Claude Code assisted with investigating the issue, implementing the change, and preparing the regression tests. The changes were validated using the project's tests and lint checks.