File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ impl Process {
80
80
rtio::Ignored => { ret.push(None); Ok(None) }
81
81
rtio::InheritFd(fd) => {
82
82
ret.push(None);
83
- Ok(Some(file::FileDesc::new(fd, true )))
83
+ Ok(Some(file::FileDesc::new(fd, false )))
84
84
}
85
85
rtio::CreatePipe(readable, _writable) => {
86
86
let (reader, writer) = try!(pipe());
Original file line number Diff line number Diff line change @@ -378,7 +378,8 @@ pub enum StdioContainer {
378
378
Ignored,
379
379
380
380
/// The specified file descriptor is inherited for the stream which it is
381
- /// specified for.
381
+ /// specified for. Ownership of the file descriptor is *not* taken, so the
382
+ /// caller must clean it up.
382
383
InheritFd(libc::c_int),
383
384
384
385
/// Creates a pipe for the specified file descriptor which will be created
@@ -605,6 +606,7 @@ impl Drop for Process {
605
606
606
607
#[cfg(test)]
607
608
mod tests {
609
+ extern crate native;
608
610
use io::process::{Command, Process};
609
611
use prelude::*;
610
612
@@ -1017,4 +1019,25 @@ mod tests {
1017
1019
assert!(Process::kill(id, 0).is_ok());
1018
1020
assert!(Process::kill(id, PleaseExitSignal).is_ok());
1019
1021
})
1022
+
1023
+ iotest!(fn dont_close_fd_on_command_spawn() {
1024
+ use std::rt::rtio::{Truncate, Write};
1025
+ use native::io::file;
1026
+
1027
+ let path = if cfg!(windows) {
1028
+ Path::new("NUL")
1029
+ } else {
1030
+ Path::new("/dev/null")
1031
+ };
1032
+
1033
+ let mut fdes = match file::open(&path.to_c_str(), Truncate, Write) {
1034
+ Ok(f) => f,
1035
+ Err(_) => fail!("failed to open file descriptor"),
1036
+ };
1037
+
1038
+ let mut cmd = pwd_cmd();
1039
+ let _ = cmd.stdout(InheritFd(fdes.fd()));
1040
+ assert!(cmd.status().unwrap().success());
1041
+ assert!(fdes.inner_write("extra write\n".as_bytes()).is_ok());
1042
+ })
1020
1043
}
You can’t perform that action at this time.
0 commit comments