@@ -17,8 +17,6 @@ use std::env::temp_dir;
1717use std:: ffi:: OsString ;
1818use std:: fs:: File ;
1919use std:: io:: { Seek , SeekFrom , Write } ;
20- use std:: os:: fd:: { AsRawFd , OwnedFd , RawFd } ;
21- use std:: os:: unix:: io:: FromRawFd ;
2220use std:: process:: { Command , Stdio } ;
2321use std:: sync:: atomic:: Ordering ;
2422use std:: sync:: { Once , atomic:: AtomicBool } ;
@@ -158,8 +156,8 @@ where
158156 } ;
159157
160158 let ( uumain_exit_status, captured_stdout, captured_stderr) = thread:: scope ( |s| {
161- let out = s. spawn ( || read_from_fd ( read_pipe_stdout. as_raw_fd ( ) ) ) ;
162- let err = s. spawn ( || read_from_fd ( read_pipe_stderr. as_raw_fd ( ) ) ) ;
159+ let out = s. spawn ( || read_from_fd ( read_pipe_stdout) ) ;
160+ let err = s. spawn ( || read_from_fd ( read_pipe_stderr) ) ;
163161 #[ allow( clippy:: unnecessary_to_owned) ]
164162 // TODO: clippy wants us to use args.iter().cloned() ?
165163 let status = uumain_function ( args. to_owned ( ) . into_iter ( ) ) ;
@@ -200,15 +198,12 @@ where
200198 }
201199}
202200
203- fn read_from_fd ( fd : RawFd ) -> String {
201+ fn read_from_fd ( fd : impl std :: os :: fd :: AsFd ) -> String {
204202 let mut captured_output = Vec :: new ( ) ;
205203 let mut read_buffer = [ 0 ; 1024 ] ;
206204
207- // Temporarily create an OwnedFd for reading (we won't drop it)
208- let owned_fd = unsafe { OwnedFd :: from_raw_fd ( fd) } ;
209-
210205 loop {
211- match read ( & owned_fd , & mut read_buffer) {
206+ match read ( & fd , & mut read_buffer) {
212207 Ok ( bytes_read) => {
213208 if bytes_read == 0 {
214209 break ;
@@ -222,9 +217,6 @@ fn read_from_fd(fd: RawFd) -> String {
222217 }
223218 }
224219
225- // Forget the owned_fd to prevent it from closing the fd (the caller owns it)
226- std:: mem:: forget ( owned_fd) ;
227-
228220 String :: from_utf8_lossy ( & captured_output) . into_owned ( )
229221}
230222
0 commit comments