Skip to content
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

No way to extract an owned RawFd from ChildStdout #5333

Closed
satakuma opened this issue Jan 3, 2023 · 3 comments · Fixed by #5899
Closed

No way to extract an owned RawFd from ChildStdout #5333

satakuma opened this issue Jan 3, 2023 · 3 comments · Fixed by #5899
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. M-process Module: tokio/process

Comments

@satakuma
Copy link
Member

satakuma commented Jan 3, 2023

Is your feature request related to a problem? Please describe.
I am trying to implement support for named Unix pipes (#5318) and I am considering adding conversion from types in tokio::process which hold a file descriptor to a pipe end. However, I've noticed that currently there is no way to turn ChildStdout, ChildStderr and ChildStdin types into an owned RawFd, even though they implement AsRawFd.

In this particular case, I can probably hack my way through internally to get the fd, but I think it would be useful to expose such conversion to the public API.

Describe the solution you'd like
Add a new method to the ChildStdout, analogous to the from_std method:

fn into_std(self) -> Result<std::process::ChildStdout>

which would perform conversion from an asynchronous ChildStdout to a synchronous one, which in turn implements IntoRawFd. Also add similar methods to ChildStderr and ChildStdin types.

Describe alternatives you've considered
Implement IntoRawFd to those types directly, but from what I can see tokio does not implement this trait for most types in favor of into_std-like methods.

@satakuma satakuma added A-tokio Area: The main tokio crate C-feature-request Category: A feature request. labels Jan 3, 2023
@Darksonn Darksonn added the M-process Module: tokio/process label Jan 3, 2023
@Darksonn
Copy link
Contributor

Darksonn commented Jan 3, 2023

Generally, the reason that we don't implement IntoRawFd is that the operation is fallible. I wouldn't mind adding an into_fd method that returns a result.

I would have to think about it when it comes to an into_std method. I recall there being some reason for not having that method, but I don't remember what it is.

@ipetkov
Copy link
Member

ipetkov commented Jan 3, 2023

@Darksonn pretty much the fallible unwrap IIRC

@satakuma
Copy link
Member Author

satakuma commented Jan 4, 2023

The into_std method was mentioned in #4403, which I failed to notice while opening this issue.
ChildStd{in,err,out} are lacking FromRawFd impls, so it is impossible to create them from tokio types. New IO safety traits for them also haven't landed yet, see rust-lang/rust#98704.

As I said, I can live without this conversion for now, but the topic of into_std methods may appear again once it becomes possible to create std types from raw file descriptors. Feel free to close this issue.

NobodyXu added a commit to NobodyXu/tokio that referenced this issue Jul 30, 2023
Fixed tokio-rs#4403 and fixed tokio-rs#5333

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
NobodyXu added a commit to NobodyXu/tokio that referenced this issue Jul 30, 2023
Fixed tokio-rs#4403 and fixed tokio-rs#5333

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
NobodyXu added a commit to NobodyXu/tokio that referenced this issue Jul 31, 2023
Fixed tokio-rs#4403 and fixed tokio-rs#5333

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
NobodyXu added a commit to NobodyXu/tokio that referenced this issue Aug 2, 2023
Fixed tokio-rs#4403 and fixed tokio-rs#5333

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
NobodyXu added a commit to NobodyXu/tokio that referenced this issue Aug 4, 2023
Fixed tokio-rs#4403 and fixed tokio-rs#5333

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
NobodyXu added a commit to NobodyXu/tokio that referenced this issue Aug 5, 2023
Fixed tokio-rs#4403 and fixed tokio-rs#5333

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
NobodyXu added a commit to NobodyXu/tokio that referenced this issue Aug 6, 2023
Fixed tokio-rs#4403 and fixed tokio-rs#5333

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
NobodyXu added a commit to NobodyXu/tokio that referenced this issue Aug 9, 2023
Fixed tokio-rs#4403 and fixed tokio-rs#5333

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. M-process Module: tokio/process
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants