diff options
| author | bors <bors@rust-lang.org> | 2016-01-11 10:19:44 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2016-01-11 10:19:44 +0000 |
| commit | d228cd3964b7cbac7665ff38bde46da67586b87d (patch) | |
| tree | 7a7ce28ffa96dc074ff662496f983ad15375044c /src/libsyntax | |
| parent | dfaddb732ced1da9d310990df095ca36f43fbc3d (diff) | |
| parent | 7f7a059c4719bbff6c2859802bc50ab2fcaf249f (diff) | |
| download | rust-d228cd3964b7cbac7665ff38bde46da67586b87d.tar.gz rust-d228cd3964b7cbac7665ff38bde46da67586b87d.zip | |
Auto merge of #30490 - ipetkov:unix-spawn, r=alexcrichton
* If the requested descriptors to inherit are stdio descriptors there
are situations where they will not be set correctly
* Example: parent's stdout --> child's stderr
parent's stderr --> child's stdout
* Solution: if the requested descriptors for the child are stdio
descriptors, `dup` them before overwriting the child's stdio
Example of a program which exhibits the bug:
```rust
// stdio.rs
use std::io::Write;
use std::io::{stdout, stderr};
use std::process::{Command, Stdio};
use std::os::unix::io::FromRawFd;
fn main() {
stdout().write_all("parent stdout\n".as_bytes()).unwrap();
stderr().write_all("parent stderr\n".as_bytes()).unwrap();
Command::new("sh")
.arg("-c")
.arg("echo 'child stdout'; echo 'child stderr' 1>&2")
.stdin(Stdio::inherit())
.stdout(unsafe { FromRawFd::from_raw_fd(2) })
.stderr(unsafe { FromRawFd::from_raw_fd(1) })
.status()
.unwrap_or_else(|e| { panic!("failed to execute process: {}", e) });
}
```
Before:
```
$ rustc --version
rustc 1.7.0-nightly (8ad12c3e2 2015-12-19)
$ rustc stdio.rs && ./stdio >out 2>err
$ cat out
parent stdout
$ cat err
parent stderr
child stdout
child stderr
```
After (expected):
```
$ rustc --version
rustc 1.7.0-dev (712eccee2 2015-12-19)
$ rustc stdio.rs && ./stdio >out 2>err
$ cat out
parent stdout
child stderr
$ cat err
parent stderr
child stdout
```
Diffstat (limited to 'src/libsyntax')
0 files changed, 0 insertions, 0 deletions
