-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Request for creating pipes with fd other than 0,1,2 #2939
base: master
Are you sure you want to change the base?
Conversation
File descriptors are not necessarily clustered near 0, and a slice doesn't seem like the right way to provide such a mapping. I personally think it would make more sense to call one function for each file descriptor (e.g. Also, it may make sense to make the caller responsible for creating the pipes themselves (via some separate object), and supply them to the function along with the desired file descriptor number, rather than having the |
While the Windows CRT does technically have the concept of fds, we should not be using them. Rust on Windows tries to be independent of the CRT, and we should not be exposing an API that ties us to the CRT. |
As far as I know, in windows once a pipe is created you can make the child process inherit the handle and pass the handle as a command line argument to the child. Or if you want to expose the
|
The child process has to use some id to connect to the pipe. Fd is a cross platform id that can be used. Otherwise some abstraction has to be created. I think that rather than creating a cross platform pipe id type, fds can be used instead. Tell me if I should created a new pipe id type. |
@Srinivasa314 AFAIU, winapi handles are direct equivalent for posix FDs.
This way arbitrary handle mapping can be achieved. |
Using |
Ah, thanks, I see now. However, I am also unsure if |
|
Please consider that in the future Rust on Windows may have targets that do not have the CRT (rust-lang/rust#58713). Therefore the implementation for this on Windows should not rely on the CRT and functions like |
Here is an article from 2004 that describes how this technique works. What worries me is this line in particular:
Is it only Vista? Is it Vista and newer? How exactly does it "not work"? |
The child can get a HANDLE from fd without using get_osfhandle from CRT.The child can call GetStartUpInfo and get the HANDLEs from the lpreserved2 field. |
|
Since the descriptors usually come from different abstractions such as |
I modified the example and described the signature of the function in https://github.com/rust-lang/rfcs/pull/2939/files#diff-4066f02fd5a441062768cca1581d30b9 |
I don't think it makes sense to center this around pipes. Yes, pipes are an important use-case of passing additional descriptors, but there are uses for passing other things to child processes, including regular files, memfds, handles to directories etc. So neither the |
I didnt think about it. Now I changed it again. If you want to know why the flags are needed that is because you have to specify them in the StartupInfo struct in windows. |
As there is nothing essential to having this code in std, this should probably be implemented in a third party crate first. It would be easier to decide on this RFC when there is a working implementation available to be tested and used. |
The reason I created this RFC is that a third party crate will have to duplicate a lot of code of std::process::Command. I will try to create a third party crate for testing purposes. EDIT: I realised that I need to duplicate more code from rust std than I thought, so if you want to see a basic implementation of the procedure then you can check this file which I made for one of my crates. (The implementation present there is specific to my crate so for it to be in rust std it should be more generalized.) |
we could restrict these fd-passing methods to a third-party crate could wrap around |
You can use fds on windows using the CRT or simulate their behaviour using StartupInfo. |
@retep998 It would be feasible to create a third party crate if std::os::windows::process::CommandExt supported modifying startupinfo or otherwise I have to use a patched version of this file in the third party crate. For std::os::unix::process::CommandExt there is a pre_exec method in which the third party crate can dup2. |
No description provided.