Skip to content

cat: refactor stdio handling - #12210

Open
xtqqczze wants to merge 1 commit into
uutils:mainfrom
xtqqczze:dd-stdin-raw
Open

cat: refactor stdio handling#12210
xtqqczze wants to merge 1 commit into
uutils:mainfrom
xtqqczze:dd-stdin-raw

Conversation

@xtqqczze

@xtqqczze xtqqczze commented May 10, 2026

Copy link
Copy Markdown
Contributor

Introduce safe wrappers for raw stdio backed by ManuallyDrop<File>. The ManuallyDrop prevents the file descriptor from being closed on drop, which could otherwise lead to undefined behavior.

The wrapper only exposes &File, so safe code cannot take ownership and accidentally drop the underlying descriptor.

@github-actions

github-actions Bot commented May 10, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/date/date-locale-hour (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/retry (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/rm/isatty (passes in this run but fails in the 'main' branch)

@xtqqczze
xtqqczze force-pushed the dd-stdin-raw branch 3 times, most recently from c2a52d4 to 07699da Compare May 10, 2026 01:47
@xtqqczze

This comment was marked as outdated.

@xtqqczze xtqqczze changed the title dd: refactor stdin handling to use StdinRaw struct dd: refactor stdio handling May 10, 2026
@xtqqczze
xtqqczze force-pushed the dd-stdin-raw branch 8 times, most recently from 2736ee9 to e95946e Compare May 10, 2026 19:36
@xtqqczze xtqqczze changed the title dd: refactor stdio handling feat: refactor stdio handling May 10, 2026
@oech3

This comment was marked as resolved.

@xtqqczze

This comment was marked as resolved.

@codspeed-hq

codspeed-hq Bot commented May 11, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 24 untouched benchmarks
⏩ 393 skipped benchmarks1


Comparing xtqqczze:dd-stdin-raw (02064e3) with main (e0ff0eb)

Open in CodSpeed

Footnotes

  1. 393 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.

@xtqqczze
xtqqczze force-pushed the dd-stdin-raw branch 2 times, most recently from 42e5ae2 to a5a2281 Compare May 13, 2026 13:15
@xtqqczze xtqqczze changed the title feat: refactor stdio handling cat: refactor stdio handling May 13, 2026
Comment thread src/uucore/src/lib/mods/stdio.rs Outdated
pub fn stdout_raw() -> StdoutRaw {
// SAFETY: We ensure that the file descriptor is never closed by
// wrapping the `File` in `ManuallyDrop`.
let fd = unsafe { rustix::stdio::take_stdout() };

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let fd = unsafe { rustix::stdio::take_stdout() };
let fd = unsafe { OwnedFd::from_raw_fd(libc::STDOUT_FILENO as RawFd) }

We could avoid the rustix dependency here if so desired.

@xtqqczze
xtqqczze marked this pull request as ready for review May 13, 2026 15:46
@xtqqczze
xtqqczze marked this pull request as draft May 21, 2026 17:49
@xtqqczze
xtqqczze marked this pull request as ready for review May 24, 2026 13:44
@xtqqczze
xtqqczze force-pushed the dd-stdin-raw branch 5 times, most recently from b6d885e to 657641d Compare September 5, 2026 07:47
@xtqqczze

xtqqczze commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

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.

2 participants