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 {
8080 rtio:: Ignored => { ret. push ( None ) ; Ok ( None ) }
8181 rtio:: InheritFd ( fd) => {
8282 ret. push ( None ) ;
83- Ok ( Some ( file:: FileDesc :: new ( fd, true ) ) )
83+ Ok ( Some ( file:: FileDesc :: new ( fd, false ) ) )
8484 }
8585 rtio:: CreatePipe ( readable, _writable) => {
8686 let ( reader, writer) = try!( pipe ( ) ) ;
Original file line number Diff line number Diff line change @@ -378,7 +378,8 @@ pub enum StdioContainer {
378378 Ignored ,
379379
380380 /// 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.
382383 InheritFd ( libc:: c_int ) ,
383384
384385 /// Creates a pipe for the specified file descriptor which will be created
@@ -605,6 +606,7 @@ impl Drop for Process {
605606
606607#[ cfg( test) ]
607608mod tests {
609+ extern crate native;
608610 use io:: process:: { Command , Process } ;
609611 use prelude:: * ;
610612
@@ -1017,4 +1019,25 @@ mod tests {
10171019 assert!( Process :: kill( id, 0 ) . is_ok( ) ) ;
10181020 assert!( Process :: kill( id, PleaseExitSignal ) . is_ok( ) ) ;
10191021 } )
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+ } )
10201043}
You can’t perform that action at this time.
0 commit comments