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

process: allow for ergonomically piping stdio of one child into another #3466

Merged
merged 6 commits into from
Jan 27, 2021

Conversation

ipetkov
Copy link
Member

@ipetkov ipetkov commented Jan 23, 2021

  • Add TryInto<Stdio> impls for ChildStd{in,out,err} for ergonomic
    conversions into std::process::Stdio so callers can perform the
    conversion without needing to manipulate raw fds/handles directly

Fixes #3465

* Add `TryInto<Stdio>` impls for `ChildStd{in,out,err}` for ergonomic
  conversions into `std::process::Stdio` so callers can perform the
  conversion without needing to manipulate raw fds/handles directly
@ipetkov ipetkov added A-tokio Area: The main tokio crate M-process Module: tokio/process relnotes labels Jan 23, 2021
Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good to me.

tokio/src/process/mod.rs Outdated Show resolved Hide resolved
@ipetkov

This comment has been minimized.

@ipetkov
Copy link
Member Author

ipetkov commented Jan 25, 2021

Turns out the tests were catching a subtle bug, namely, not resetting the O_NONBLOCK flag (which is what most programs expect for stdio anyway).

Requesting a re-review for the new logic that was added!

@ipetkov ipetkov requested a review from Darksonn January 25, 2021 00:23
Comment on lines +182 to +186
// Ensure that the fd to be inherited is set to *blocking* mode, as this
// is the default that virtually all programs expect to have. Those
// programs that know how to work with nonblocking stdio will know how to
// change it to nonblocking mode.
set_nonblocking(&mut fd, false)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is ok because neither end of the pipe is actually used in Tokio?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. One end of the pipe should be owned by the child process (and already closed in the parent). The other end of the pipe is moved into this function, and calling .into_inner() unwraps the PollEvented and deregisters it from the reactor.

Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the test passes, then this is good to me.

@ipetkov ipetkov merged commit 34f1d3d into master Jan 27, 2021
@ipetkov ipetkov deleted the ivan/process-pipe-stdio branch January 27, 2021 01:12
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 M-process Module: tokio/process
Projects
None yet
Development

Successfully merging this pull request may close these issues.

process: support ergonomic piping of stdio of one child process to another
2 participants