Skip to content

cat: refactor stdio handling#12210

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

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

Conversation

@xtqqczze
Copy link
Copy Markdown
Contributor

@xtqqczze xtqqczze commented May 10, 2026

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 from StdinRaw, so safe code cannot take ownership and accidentally drop the underlying descriptor.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 10, 2026

GNU testsuite comparison:

GNU test failed: tests/timeout/timeout-group. tests/timeout/timeout-group is passing on 'main'. Maybe you have to rebase?
Skip an intermittent issue tests/rm/isatty (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/tail-n0f (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/date/date-locale-hour (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/printf/printf-surprise is now passing!

@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
Copy link
Copy Markdown
Contributor

oech3 commented May 11, 2026

It is logically possible to drop() wrapped safe code by enduser of uucore.
I surely need BorrowedFile...

@xtqqczze

This comment was marked as resolved.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 11, 2026

Merging this PR will not alter performance

✅ 317 untouched benchmarks
⏩ 46 skipped benchmarks1


Comparing xtqqczze:dd-stdin-raw (4df6629) with main (0c21cb9)

Open in CodSpeed

Footnotes

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

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