@@ -170,7 +170,6 @@ impl Child {
170
170
( s, r)
171
171
}
172
172
173
-
174
173
// Called when a child exits.
175
174
unsafe extern "system" fn callback( _: * mut c_void, _: BOOLEAN ) {
176
175
callback_channel( ) . 0 . try_send( ( ) ) . ok( ) ;
@@ -485,7 +484,7 @@ impl ChildStdin {
485
484
Ok ( self . 0 . into_inner( ) . await . into( ) )
486
485
} else if #[ cfg( unix) ] {
487
486
let child_stdin = self . 0 . into_inner( ) ?;
488
- blocking_fd( child_stdin . as_raw_fd ( ) ) ?;
487
+ blocking_fd( rustix :: fd :: AsFd :: as_fd ( & child_stdin ) ) ?;
489
488
Ok ( child_stdin. into( ) )
490
489
}
491
490
}
@@ -577,7 +576,7 @@ impl ChildStdout {
577
576
Ok ( self . 0 . into_inner( ) . await . into( ) )
578
577
} else if #[ cfg( unix) ] {
579
578
let child_stdout = self . 0 . into_inner( ) ?;
580
- blocking_fd( child_stdout . as_raw_fd ( ) ) ?;
579
+ blocking_fd( rustix :: fd :: AsFd :: as_fd ( & child_stdout ) ) ?;
581
580
Ok ( child_stdout. into( ) )
582
581
}
583
582
}
@@ -650,7 +649,7 @@ impl ChildStderr {
650
649
Ok ( self . 0 . into_inner( ) . await . into( ) )
651
650
} else if #[ cfg( unix) ] {
652
651
let child_stderr = self . 0 . into_inner( ) ?;
653
- blocking_fd( child_stderr . as_raw_fd ( ) ) ?;
652
+ blocking_fd( rustix :: fd :: AsFd :: as_fd ( & child_stderr ) ) ?;
654
653
Ok ( child_stderr. into( ) )
655
654
}
656
655
}
@@ -1063,22 +1062,9 @@ impl fmt::Debug for Command {
1063
1062
1064
1063
/// Moves `Fd` out of non-blocking mode.
1065
1064
#[ cfg( unix) ]
1066
- fn blocking_fd ( fd : std:: os:: unix:: io:: RawFd ) -> io:: Result < ( ) > {
1067
- // Helper macro to execute a system call that returns an `io::Result`.
1068
- macro_rules! syscall {
1069
- ( $fn: ident ( $( $arg: expr) ,* $( , ) ? ) ) => { {
1070
- let res = unsafe { libc:: $fn( $( $arg, ) * ) } ;
1071
- if res == -1 {
1072
- return Err ( std:: io:: Error :: last_os_error( ) ) ;
1073
- } else {
1074
- res
1075
- }
1076
- } } ;
1077
- }
1078
-
1079
- let res = syscall ! ( fcntl( fd, libc:: F_GETFL ) ) ;
1080
- syscall ! ( fcntl( fd, libc:: F_SETFL , res & !libc:: O_NONBLOCK ) ) ;
1081
-
1065
+ fn blocking_fd ( fd : rustix:: fd:: BorrowedFd < ' _ > ) -> io:: Result < ( ) > {
1066
+ let flags = rustix:: fs:: fcntl_getfl ( fd) ?;
1067
+ rustix:: fs:: fcntl_setfl ( fd, flags & !rustix:: fs:: OFlags :: NONBLOCK ) ?;
1082
1068
Ok ( ( ) )
1083
1069
}
1084
1070
0 commit comments