dd: remove unnecessary fcntl dependency for stdout#12208
Open
kimjune01 wants to merge 1 commit intouutils:mainfrom
Open
dd: remove unnecessary fcntl dependency for stdout#12208kimjune01 wants to merge 1 commit intouutils:mainfrom
kimjune01 wants to merge 1 commit intouutils:mainfrom
Conversation
Replace OwnedFileDescriptorOrHandle::from() with borrowed File pattern using ManuallyDrop and from_raw_fd/from_raw_handle. This eliminates the unnecessary fcntl syscall from try_clone_to_owned() when dd writes to stdout, fixing failures in restricted containers where fcntl is unavailable. Fixes uutils#12157
Contributor
|
Can we do same things without unsafe at least on unix? |
xtqqczze
reviewed
May 10, 2026
| let file = ManuallyDrop::new(unsafe { File::from_raw_handle(io::stdout().as_raw_handle()) }); | ||
|
|
||
| Self::prepare_file(fx.into_file(), settings) | ||
| Self::prepare_file(ManuallyDrop::into_inner(file), settings) |
Contributor
There was a problem hiding this comment.
This is potentially unsound, we must guarantee stdout is never dropped.
Contributor
I don't think so, but we can use a safe wrapper: #12210 |
Contributor
|
|
Contributor
[Edit] this spreads |
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.
Summary
ddfails in restricted containers wherefcntlreturnsENOSYSbecausetry_clone_to_owned()internally callsfcntl. This was introduced in PR #10235.OwnedFileDescriptorOrHandle::from(io::stdout())with aManuallyDrop<File>wrapper that borrows the fd without cloningfcntlsyscallfrom_raw_fd) and Windows (from_raw_handle)Test plan
echo "test" | dd bs=1)Fixes #12157