rust/src/libstd/sys/unix
bors d228cd3964 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
```
2016-01-11 10:19:44 +00:00
..
backtrace some more clippy-based improvements 2015-09-08 00:36:29 +02:00
ext doc: fix typo 2015-12-30 19:31:28 +02:00
condvar.rs std: Add Instant and SystemTime to std::time 2015-11-19 09:32:38 -08:00
fd.rs Fix a typo in fd.rs. Fixes #30231. 2015-12-08 12:38:37 -06:00
fs.rs std: Remove rust_builtin C support library 2015-12-21 22:12:48 -08:00
mod.rs Fix warnings when compiling stdlib with --test 2015-12-29 16:07:01 +01:00
mutex.rs std: Migrate to the new libc 2015-11-09 22:55:50 -08:00
net.rs std: Migrate to the new libc 2015-11-09 22:55:50 -08:00
os.rs std: Remove rust_builtin C support library 2015-12-21 22:12:48 -08:00
os_str.rs std: Stabilize APIs for the 1.6 release 2015-12-05 15:09:44 -08:00
pipe.rs Register new snapshots 2015-08-11 15:11:13 -07:00
process.rs Auto merge of #30490 - ipetkov:unix-spawn, r=alexcrichton 2016-01-11 10:19:44 +00:00
rwlock.rs std: Migrate to the new libc 2015-11-09 22:55:50 -08:00
stack_overflow.rs Fix warnings when compiling stdlib with --test 2015-12-29 16:07:01 +01:00
stdio.rs some more clippy-based improvements 2015-09-08 00:36:29 +02:00
thread.rs Add JoinHandleExt to get the pthread_t on unix platforms 2015-12-04 20:09:32 -05:00
thread_local.rs std: Migrate to the new libc 2015-11-09 22:55:50 -08:00
time.rs Fix the time overflow on mac as well 2015-12-04 09:49:35 -07:00