diff options
| author | bors <bors@rust-lang.org> | 2014-08-13 05:56:20 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-08-13 05:56:20 +0000 |
| commit | 9d554212de0398ac044e6d815da3bfb184831e77 (patch) | |
| tree | 817cbc7ed38cda683ae4af90140fff44d5db4b73 /src/libstd | |
| parent | 6291781592ff079fc1e84f4b8be5684d2a52b8bd (diff) | |
| parent | 3fe0ba9afc7504ec01a778d8d72bd0b72fd013e1 (diff) | |
| download | rust-9d554212de0398ac044e6d815da3bfb184831e77.tar.gz rust-9d554212de0398ac044e6d815da3bfb184831e77.zip | |
auto merge of #16421 : ipetkov/rust/cmd-fd-fix-retry, r=alexcrichton
Retry pull requesting of https://github.com/rust-lang/rust/pull/16407 after accidentally messing up rebasing of branches and making bors think the PR was merged
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/io/process.rs | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs index 1eee6983494..c82b4831341 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/io/process.rs @@ -378,7 +378,8 @@ pub enum StdioContainer { Ignored, /// The specified file descriptor is inherited for the stream which it is - /// specified for. + /// specified for. Ownership of the file descriptor is *not* taken, so the + /// caller must clean it up. InheritFd(libc::c_int), /// Creates a pipe for the specified file descriptor which will be created @@ -605,6 +606,7 @@ impl Drop for Process { #[cfg(test)] mod tests { + extern crate native; use io::process::{Command, Process}; use prelude::*; @@ -1017,4 +1019,25 @@ mod tests { assert!(Process::kill(id, 0).is_ok()); assert!(Process::kill(id, PleaseExitSignal).is_ok()); }) + + iotest!(fn dont_close_fd_on_command_spawn() { + use std::rt::rtio::{Truncate, Write}; + use native::io::file; + + let path = if cfg!(windows) { + Path::new("NUL") + } else { + Path::new("/dev/null") + }; + + let mut fdes = match file::open(&path.to_c_str(), Truncate, Write) { + Ok(f) => f, + Err(_) => fail!("failed to open file descriptor"), + }; + + let mut cmd = pwd_cmd(); + let _ = cmd.stdout(InheritFd(fdes.fd())); + assert!(cmd.status().unwrap().success()); + assert!(fdes.inner_write("extra write\n".as_bytes()).is_ok()); + }) } |
