@@ -13,7 +13,7 @@ use crate::sys::fd::FileDesc;
13
13
use crate :: sys:: fs:: File ;
14
14
use crate :: sys:: pipe:: { self , AnonPipe } ;
15
15
use crate :: sys_common:: process:: { CommandEnv , CommandEnvs } ;
16
- use crate :: sys_common:: IntoInner ;
16
+ use crate :: sys_common:: { FromInner , IntoInner } ;
17
17
18
18
#[ cfg( not( target_os = "fuchsia" ) ) ]
19
19
use crate :: sys:: fs:: OpenOptions ;
@@ -150,6 +150,7 @@ pub enum Stdio {
150
150
Null ,
151
151
MakePipe ,
152
152
Fd ( FileDesc ) ,
153
+ StaticFd ( BorrowedFd < ' static > ) ,
153
154
}
154
155
155
156
#[ derive( Copy , Clone , Debug , Eq , PartialEq ) ]
@@ -463,6 +464,11 @@ impl Stdio {
463
464
}
464
465
}
465
466
467
+ Stdio :: StaticFd ( fd) => {
468
+ let fd = FileDesc :: from_inner ( fd. try_clone_to_owned ( ) ?) ;
469
+ Ok ( ( ChildStdio :: Owned ( fd) , None ) )
470
+ }
471
+
466
472
Stdio :: MakePipe => {
467
473
let ( reader, writer) = pipe:: anon_pipe ( ) ?;
468
474
let ( ours, theirs) = if readable { ( writer, reader) } else { ( reader, writer) } ;
@@ -497,6 +503,28 @@ impl From<File> for Stdio {
497
503
}
498
504
}
499
505
506
+ impl From < io:: Stdout > for Stdio {
507
+ fn from ( _: io:: Stdout ) -> Stdio {
508
+ // This ought really to be is Stdio::StaticFd(input_argument.as_fd()).
509
+ // But AsFd::as_fd takes its argument by reference, and yields
510
+ // a bounded lifetime, so it's no use here. There is no AsStaticFd.
511
+ //
512
+ // Additionally AsFd is only implemented for the *locked* versions.
513
+ // We don't want to lock them here. (The implications of not locking
514
+ // are the same as those for process::Stdio::inherit().)
515
+ //
516
+ // Arguably the hypothetical AsStaticFd and AsFd<'static>
517
+ // should be implemented for io::Stdout, not just for StdoutLocked.
518
+ Stdio :: StaticFd ( unsafe { BorrowedFd :: borrow_raw ( libc:: STDOUT_FILENO ) } )
519
+ }
520
+ }
521
+
522
+ impl From < io:: Stderr > for Stdio {
523
+ fn from ( _: io:: Stderr ) -> Stdio {
524
+ Stdio :: StaticFd ( unsafe { BorrowedFd :: borrow_raw ( libc:: STDERR_FILENO ) } )
525
+ }
526
+ }
527
+
500
528
impl ChildStdio {
501
529
pub fn fd ( & self ) -> Option < c_int > {
502
530
match * self {
0 commit comments