uucore: emulate GNU close_stdout / close_stream behaviour - #13999
Open
sylvestre wants to merge 1 commit into
Open
uucore: emulate GNU close_stdout / close_stream behaviour#13999sylvestre wants to merge 1 commit into
sylvestre wants to merge 1 commit into
Conversation
GNU coreutils use close_stdout() (from gnulib) to flush stdout at exit and report write errors. Key behaviours: - Exit 1 if flush fails (e.g. writing to /dev/full) - Silence EBADF when stdout was already closed at startup (prog >&-) and the program produced no output - Silence BrokenPipe (normal pipe shutdown) In Rust the bin! macro previously only printed a message on flush failure without exiting non-zero. Fix this by: 1. Detecting whether fd 1 is open at startup via /proc/self/fd/1 (before any allocation can claim fd 1) 2. Flushing stdout in bin_inner! after uumain and exiting 1 on error, unless the error is BrokenPipe or EBADF-on-initially-closed-stdout This fixes the /dev/full cases in tests/misc/close-stdout.sh.
oech3
reviewed
Aug 18, 2026
| // start). We use /proc/self/fd/1 to avoid a libc dependency. | ||
| #[cfg(unix)] | ||
| let stdout_initially_open: bool = | ||
| std::path::Path::new("/proc/self/fd/1").exists(); |
Contributor
There was a problem hiding this comment.
It does not work if /proc is masked.
Collaborator
|
This reintroduce a bug in cksum, when doing Additionally, it renders the split between |
|
GNU testsuite comparison: |
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.
GNU coreutils use
close_stdout()(from gnulib) to flush stdout at exit and report write errors. Key behaviours:/dev/full)prog >&-) and the program produced no outputIn Rust the
bin!macro previously only printed a message on flush failure without exiting non-zero. Fix this by:/proc/self/fd/1(before any allocation can claim fd 1)bin_inner!afteruumainand exiting 1 on error, unless the error is BrokenPipe or EBADF-on-initially-closed-stdoutThe flush logic is moved from
bin!intobin_inner!sostdout_initially_openis in scope.This fixes the
/dev/fullcases intests/misc/close-stdout.sh.