@@ -10,7 +10,7 @@ use libc::{c_int, pid_t};
10
10
) ) ) ]
11
11
use libc:: { gid_t, uid_t} ;
12
12
13
- use crate :: io:: { self , Error , ErrorKind } ;
13
+ use crate :: io;
14
14
use crate :: num:: NonZero ;
15
15
use crate :: sys:: cvt;
16
16
#[ cfg( target_os = "linux" ) ]
@@ -60,12 +60,7 @@ impl Command {
60
60
61
61
let envp = self . capture_env ( ) ;
62
62
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 ( ) ?;
69
64
70
65
let ( ours, theirs) = self . setup_io ( default, needs_stdin) ?;
71
66
@@ -146,7 +141,7 @@ impl Command {
146
141
) ;
147
142
let errno = i32:: from_be_bytes ( errno. try_into ( ) . unwrap ( ) ) ;
148
143
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) ) ;
150
145
}
151
146
Err ( ref e) if e. is_interrupted ( ) => { }
152
147
Err ( e) => {
@@ -175,8 +170,8 @@ impl Command {
175
170
// allowed to exist in dead code), but it sounds bad, so we go out of our
176
171
// way to avoid that all-together.
177
172
#[ 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 ,
180
175
"`fork`+`exec`-based process spawning is not supported on this target" ,
181
176
) ;
182
177
@@ -219,7 +214,7 @@ impl Command {
219
214
thread:: sleep ( delay) ;
220
215
} else {
221
216
return Err ( io:: const_io_error!(
222
- ErrorKind :: WouldBlock ,
217
+ io :: ErrorKind :: WouldBlock ,
223
218
"forking returned EBADF too often" ,
224
219
) ) ;
225
220
}
@@ -234,8 +229,8 @@ impl Command {
234
229
pub fn exec ( & mut self , default : Stdio ) -> io:: Error {
235
230
let envp = self . capture_env ( ) ;
236
231
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 ;
239
234
}
240
235
241
236
match self . setup_io ( default, true ) {
@@ -561,7 +556,7 @@ impl Command {
561
556
thread:: sleep ( delay) ;
562
557
} else {
563
558
return Err ( io:: const_io_error!(
564
- ErrorKind :: WouldBlock ,
559
+ io :: ErrorKind :: WouldBlock ,
565
560
"posix_spawnp returned EBADF too often" ,
566
561
) ) ;
567
562
}
@@ -729,7 +724,7 @@ impl Command {
729
724
// But we cannot obtain its pid even though pidfd_getpid support was verified earlier.
730
725
// This might happen if libc can't open procfs because the file descriptor limit has been reached.
731
726
libc:: close ( pidfd) ;
732
- return Err ( Error :: new (
727
+ return Err ( io :: Error :: new (
733
728
e. kind ( ) ,
734
729
"pidfd_spawnp succeeded but the child's PID could not be obtained" ,
735
730
) ) ;
@@ -1190,7 +1185,6 @@ impl ExitStatusError {
1190
1185
mod linux_child_ext {
1191
1186
1192
1187
use crate :: os:: linux:: process as os;
1193
- use crate :: sys:: pal:: unix:: ErrorKind ;
1194
1188
use crate :: sys:: pal:: unix:: linux:: pidfd as imp;
1195
1189
use crate :: sys_common:: FromInner ;
1196
1190
use crate :: { io, mem} ;
@@ -1203,7 +1197,9 @@ mod linux_child_ext {
1203
1197
. as_ref ( )
1204
1198
// SAFETY: The os type is a transparent wrapper, therefore we can transmute references
1205
1199
. 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
+ } )
1207
1203
}
1208
1204
1209
1205
fn into_pidfd ( mut self ) -> Result < os:: PidFd , Self > {
0 commit comments