@@ -243,13 +243,15 @@ impl Command {
243
243
244
244
fn spawn_inner ( & self , default_io : StdioImp ) -> io:: Result < Child > {
245
245
let default_io = Stdio ( default_io) ;
246
- let ( their_stdin, our_stdin) = try!(
246
+
247
+ // See comment on `setup_io` for what `_drop_later` is.
248
+ let ( their_stdin, our_stdin, _drop_later) = try!(
247
249
setup_io ( self . stdin . as_ref ( ) . unwrap_or ( & default_io) , true )
248
250
) ;
249
- let ( their_stdout, our_stdout) = try!(
251
+ let ( their_stdout, our_stdout, _drop_later ) = try!(
250
252
setup_io ( self . stdout . as_ref ( ) . unwrap_or ( & default_io) , false )
251
253
) ;
252
- let ( their_stderr, our_stderr) = try!(
254
+ let ( their_stderr, our_stderr, _drop_later ) = try!(
253
255
setup_io ( self . stderr . as_ref ( ) . unwrap_or ( & default_io) , false )
254
256
) ;
255
257
@@ -271,7 +273,7 @@ impl Command {
271
273
/// By default, stdin, stdout and stderr are inherited from the parent.
272
274
#[ stable( feature = "process" , since = "1.0.0" ) ]
273
275
pub fn spawn ( & mut self ) -> io:: Result < Child > {
274
- self . spawn_inner ( StdioImp :: Raw ( imp :: Stdio :: Inherit ) )
276
+ self . spawn_inner ( StdioImp :: Inherit )
275
277
}
276
278
277
279
/// Executes the command as a child process, waiting for it to finish and
@@ -341,19 +343,30 @@ impl AsInnerMut<imp::Command> for Command {
341
343
fn as_inner_mut ( & mut self ) -> & mut imp:: Command { & mut self . inner }
342
344
}
343
345
346
+ // Takes a `Stdio` configuration (this module) and whether the to-be-owned
347
+ // handle will be readable.
348
+ //
349
+ // Returns a triple of (stdio to spawn with, stdio to store, stdio to drop). The
350
+ // stdio to spawn with is passed down to the `sys` module and indicates how the
351
+ // stdio stream should be set up. The "stdio to store" is an object which
352
+ // should be returned in the `Child` that makes its way out. The "stdio to drop"
353
+ // represents the raw value of "stdio to spawn with", but is the owned variant
354
+ // for it. This needs to be dropped after the child spawns
344
355
fn setup_io ( io : & Stdio , readable : bool )
345
- -> io:: Result < ( imp:: Stdio , Option < AnonPipe > ) >
356
+ -> io:: Result < ( imp:: Stdio , Option < AnonPipe > , Option < AnonPipe > ) >
346
357
{
347
358
Ok ( match io. 0 {
348
359
StdioImp :: MakePipe => {
349
360
let ( reader, writer) = try!( pipe:: anon_pipe ( ) ) ;
350
361
if readable {
351
- ( imp:: Stdio :: Piped ( reader) , Some ( writer) )
362
+ ( imp:: Stdio :: Raw ( reader. raw ( ) ) , Some ( writer) , Some ( reader ) )
352
363
} else {
353
- ( imp:: Stdio :: Piped ( writer) , Some ( reader) )
364
+ ( imp:: Stdio :: Raw ( writer. raw ( ) ) , Some ( reader) , Some ( writer ) )
354
365
}
355
366
}
356
- StdioImp :: Raw ( ref raw) => ( raw. clone_if_copy ( ) , None ) ,
367
+ StdioImp :: Raw ( ref owned) => ( imp:: Stdio :: Raw ( owned. raw ( ) ) , None , None ) ,
368
+ StdioImp :: Inherit => ( imp:: Stdio :: Inherit , None , None ) ,
369
+ StdioImp :: None => ( imp:: Stdio :: None , None , None ) ,
357
370
} )
358
371
}
359
372
@@ -379,7 +392,9 @@ pub struct Stdio(StdioImp);
379
392
// The internal enum for stdio setup; see below for descriptions.
380
393
enum StdioImp {
381
394
MakePipe ,
382
- Raw ( imp:: Stdio ) ,
395
+ Raw ( imp:: RawStdio ) ,
396
+ Inherit ,
397
+ None ,
383
398
}
384
399
385
400
impl Stdio {
@@ -389,16 +404,16 @@ impl Stdio {
389
404
390
405
/// The child inherits from the corresponding parent descriptor.
391
406
#[ stable( feature = "process" , since = "1.0.0" ) ]
392
- pub fn inherit ( ) -> Stdio { Stdio ( StdioImp :: Raw ( imp :: Stdio :: Inherit ) ) }
407
+ pub fn inherit ( ) -> Stdio { Stdio ( StdioImp :: Inherit ) }
393
408
394
409
/// This stream will be ignored. This is the equivalent of attaching the
395
410
/// stream to `/dev/null`
396
411
#[ stable( feature = "process" , since = "1.0.0" ) ]
397
- pub fn null ( ) -> Stdio { Stdio ( StdioImp :: Raw ( imp :: Stdio :: None ) ) }
412
+ pub fn null ( ) -> Stdio { Stdio ( StdioImp :: None ) }
398
413
}
399
414
400
- impl FromInner < imp:: Stdio > for Stdio {
401
- fn from_inner ( inner : imp:: Stdio ) -> Stdio {
415
+ impl FromInner < imp:: RawStdio > for Stdio {
416
+ fn from_inner ( inner : imp:: RawStdio ) -> Stdio {
402
417
Stdio ( StdioImp :: Raw ( inner) )
403
418
}
404
419
}
0 commit comments