@@ -10,7 +10,7 @@ use libc::{c_int, pid_t};
1010) ) ) ]
1111use libc:: { gid_t, uid_t} ;
1212
13- use crate :: io:: { self , Error , ErrorKind } ;
13+ use crate :: io;
1414use crate :: num:: NonZero ;
1515use crate :: sys:: cvt;
1616#[ cfg( target_os = "linux" ) ]
@@ -60,12 +60,7 @@ impl Command {
6060
6161 let envp = self . capture_env ( ) ;
6262
63- if self . saw_nul ( ) {
64- return Err ( io:: const_io_error!(
65- ErrorKind :: InvalidInput ,
66- "nul byte found in provided data" ,
67- ) ) ;
68- }
63+ self . validate_input ( ) ?;
6964
7065 let ( ours, theirs) = self . setup_io ( default, needs_stdin) ?;
7166
@@ -146,7 +141,7 @@ impl Command {
146141 ) ;
147142 let errno = i32:: from_be_bytes ( errno. try_into ( ) . unwrap ( ) ) ;
148143 assert ! ( p. wait( ) . is_ok( ) , "wait() should either return Ok or panic" ) ;
149- return Err ( Error :: from_raw_os_error ( errno) ) ;
144+ return Err ( io :: Error :: from_raw_os_error ( errno) ) ;
150145 }
151146 Err ( ref e) if e. is_interrupted ( ) => { }
152147 Err ( e) => {
@@ -175,8 +170,8 @@ impl Command {
175170 // allowed to exist in dead code), but it sounds bad, so we go out of our
176171 // way to avoid that all-together.
177172 #[ cfg( any( target_os = "tvos" , target_os = "watchos" ) ) ]
178- const ERR_APPLE_TV_WATCH_NO_FORK_EXEC : Error = io:: const_io_error!(
179- ErrorKind :: Unsupported ,
173+ const ERR_APPLE_TV_WATCH_NO_FORK_EXEC : io :: Error = io:: const_io_error!(
174+ io :: ErrorKind :: Unsupported ,
180175 "`fork`+`exec`-based process spawning is not supported on this target" ,
181176 ) ;
182177
@@ -219,7 +214,7 @@ impl Command {
219214 thread:: sleep ( delay) ;
220215 } else {
221216 return Err ( io:: const_io_error!(
222- ErrorKind :: WouldBlock ,
217+ io :: ErrorKind :: WouldBlock ,
223218 "forking returned EBADF too often" ,
224219 ) ) ;
225220 }
@@ -234,8 +229,8 @@ impl Command {
234229 pub fn exec ( & mut self , default : Stdio ) -> io:: Error {
235230 let envp = self . capture_env ( ) ;
236231
237- if self . saw_nul ( ) {
238- return io :: const_io_error! ( ErrorKind :: InvalidInput , "nul byte found in provided data" , ) ;
232+ if let Err ( err ) = self . validate_input ( ) {
233+ return err ;
239234 }
240235
241236 match self . setup_io ( default, true ) {
@@ -561,7 +556,7 @@ impl Command {
561556 thread:: sleep ( delay) ;
562557 } else {
563558 return Err ( io:: const_io_error!(
564- ErrorKind :: WouldBlock ,
559+ io :: ErrorKind :: WouldBlock ,
565560 "posix_spawnp returned EBADF too often" ,
566561 ) ) ;
567562 }
@@ -729,7 +724,7 @@ impl Command {
729724 // But we cannot obtain its pid even though pidfd_getpid support was verified earlier.
730725 // This might happen if libc can't open procfs because the file descriptor limit has been reached.
731726 libc:: close ( pidfd) ;
732- return Err ( Error :: new (
727+ return Err ( io :: Error :: new (
733728 e. kind ( ) ,
734729 "pidfd_spawnp succeeded but the child's PID could not be obtained" ,
735730 ) ) ;
@@ -1190,7 +1185,6 @@ impl ExitStatusError {
11901185mod linux_child_ext {
11911186
11921187 use crate :: os:: linux:: process as os;
1193- use crate :: sys:: pal:: unix:: ErrorKind ;
11941188 use crate :: sys:: pal:: unix:: linux:: pidfd as imp;
11951189 use crate :: sys_common:: FromInner ;
11961190 use crate :: { io, mem} ;
@@ -1203,7 +1197,9 @@ mod linux_child_ext {
12031197 . as_ref ( )
12041198 // SAFETY: The os type is a transparent wrapper, therefore we can transmute references
12051199 . map ( |fd| unsafe { mem:: transmute :: < & imp:: PidFd , & os:: PidFd > ( fd) } )
1206- . ok_or_else ( || io:: Error :: new ( ErrorKind :: Uncategorized , "No pidfd was created." ) )
1200+ . ok_or_else ( || {
1201+ io:: Error :: new ( io:: ErrorKind :: Uncategorized , "No pidfd was created." )
1202+ } )
12071203 }
12081204
12091205 fn into_pidfd ( mut self ) -> Result < os:: PidFd , Self > {
0 commit comments