Implement From<OwnedFd/Handle> for ChildStdin/out/err object by vthib · Pull Request #98704 · rust-lang/rust (original) (raw)
Summary
Comments in library/std/src/process.rs
( ab08639 ) indicates that ChildStdin
, ChildStdout
, ChildStderr
implements some traits that are not actually implemented: FromRawFd
, FromRawHandle
, and the From<OwnedFd>/From<OwnedHandle>
from the io_safety feature.
In this PR I implement FromRawHandle
and FromRawFd
for those 3 objects.
Usecase
I have a usecase where those implementations are basically needed. I want to customize
in the Command::spawn
API how the pipes for the parent/child communications are created (mainly to strengthen the security attributes on them). I can properly setup the pipes,
and the "child" handles can be provided to Child::spawn
easily using Stdio::from_raw_handle
. However, there is no way to generate the ChildStd*
objects from the raw handle of the created name pipe, which would be very useful to still expose the same API
than in other OS (basically a spawn(...) -> (Child, ChildStdin, ChildStdout, ChildSterr)
, where on windows this is customized), and to for example use tokio::ChildStdin::from_std
afterwards.
Questions
- Are those impls OK to add? I have searched to see if those impls were missing on purpose, or if it was just never implemented because never needed. I haven't found any indication on why they couldn't be added, although the user clearly has to be very careful that the handle provided makes sense (i think, mainly that it is in overlapped mode for windows).
- If this change is ok, adding the impls for the io_safety feature would probably be best, or should it be done in another PR?
- I just copy-pasted the
#[stable(...)]
attributes, but thesince
value has to be updated, I'm not sure to which value.