@@ -270,19 +270,22 @@ impl Command {
270270 }
271271
272272 if let Some ( fd) = stdio. stderr . fd ( ) {
273- let _ = syscall:: close ( 2 ) ;
274- t ! ( cvt( syscall:: dup( fd, & [ ] ) ) ) ;
275- let _ = syscall:: close ( fd) ;
273+ t ! ( cvt( syscall:: dup2( fd, 2 , & [ ] ) ) ) ;
274+ let mut flags = t ! ( cvt( syscall:: fcntl( 2 , syscall:: F_GETFL , 0 ) ) ) ;
275+ flags &= ! syscall:: O_CLOEXEC ;
276+ t ! ( cvt( syscall:: fcntl( 2 , syscall:: F_SETFL , flags) ) ) ;
276277 }
277278 if let Some ( fd) = stdio. stdout . fd ( ) {
278- let _ = syscall:: close ( 1 ) ;
279- t ! ( cvt( syscall:: dup( fd, & [ ] ) ) ) ;
280- let _ = syscall:: close ( fd) ;
279+ t ! ( cvt( syscall:: dup2( fd, 1 , & [ ] ) ) ) ;
280+ let mut flags = t ! ( cvt( syscall:: fcntl( 1 , syscall:: F_GETFL , 0 ) ) ) ;
281+ flags &= ! syscall:: O_CLOEXEC ;
282+ t ! ( cvt( syscall:: fcntl( 1 , syscall:: F_SETFL , flags) ) ) ;
281283 }
282284 if let Some ( fd) = stdio. stdin . fd ( ) {
283- let _ = syscall:: close ( 0 ) ;
284- t ! ( cvt( syscall:: dup( fd, & [ ] ) ) ) ;
285- let _ = syscall:: close ( fd) ;
285+ t ! ( cvt( syscall:: dup2( fd, 0 , & [ ] ) ) ) ;
286+ let mut flags = t ! ( cvt( syscall:: fcntl( 0 , syscall:: F_GETFL , 0 ) ) ) ;
287+ flags &= ! syscall:: O_CLOEXEC ;
288+ t ! ( cvt( syscall:: fcntl( 0 , syscall:: F_SETFL , flags) ) ) ;
286289 }
287290
288291 if let Some ( g) = self . gid {
0 commit comments