File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -280,11 +280,21 @@ fn exec_with_pipe(mut cmd: Command, input: &[u8]) {
280
280
use std:: process:: Stdio ;
281
281
282
282
let mut fds: [ libc:: c_int ; 2 ] = [ 0 , 0 ] ;
283
- // We need to set close-on-exec, otherwise our pipe isn't readable after exec
284
283
// SAFETY: fds is an array of 2 libc::c_int
285
- let res = unsafe { libc:: pipe2 ( fds. as_mut_ptr ( ) , libc:: O_CLOEXEC ) } ;
286
- if res != 0 {
287
- panic ! ( "failed to create a pipe" ) ;
284
+ let res = unsafe { libc:: pipe ( fds. as_mut_ptr ( ) ) } ;
285
+ assert_eq ! ( res, 0 , "failed to create pipe" ) ;
286
+
287
+ // We need to set close-on-exec, otherwise our pipe isn't readable after exec
288
+ // SAFETY: fcntl has no preconditions
289
+ unsafe {
290
+ for fd in & fds {
291
+ let res = libc:: fcntl (
292
+ * fd,
293
+ libc:: F_SETFD ,
294
+ libc:: fcntl ( * fd, libc:: F_GETFD ) | libc:: FD_CLOEXEC ,
295
+ ) ;
296
+ assert_eq ! ( res, 0 , "failed to set close-on-exec for pipe" ) ;
297
+ }
288
298
}
289
299
290
300
// SAFETY: Both elements of fds are open file descriptors, because pipe2 returned 0
You can’t perform that action at this time.
0 commit comments