@@ -10,13 +10,12 @@ 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 } ;
14
13
use crate :: num:: NonZero ;
15
14
use crate :: sys:: cvt;
16
15
#[ cfg( target_os = "linux" ) ]
17
16
use crate :: sys:: pal:: unix:: linux:: pidfd:: PidFd ;
18
17
use crate :: sys:: process:: process_common:: * ;
19
- use crate :: { fmt, mem, sys} ;
18
+ use crate :: { fmt, io , mem, sys} ;
20
19
21
20
cfg_if:: cfg_if! {
22
21
// This workaround is only needed for QNX 7.0 and 7.1. The bug should have been fixed in 8.0
@@ -60,12 +59,7 @@ impl Command {
60
59
61
60
let envp = self . capture_env ( ) ;
62
61
63
- if self . saw_nul ( ) {
64
- return Err ( io:: const_io_error!(
65
- ErrorKind :: InvalidInput ,
66
- "nul byte found in provided data" ,
67
- ) ) ;
68
- }
62
+ self . validate_input ( ) ?;
69
63
70
64
let ( ours, theirs) = self . setup_io ( default, needs_stdin) ?;
71
65
@@ -146,7 +140,7 @@ impl Command {
146
140
) ;
147
141
let errno = i32:: from_be_bytes ( errno. try_into ( ) . unwrap ( ) ) ;
148
142
assert ! ( p. wait( ) . is_ok( ) , "wait() should either return Ok or panic" ) ;
149
- return Err ( Error :: from_raw_os_error ( errno) ) ;
143
+ return Err ( io :: Error :: from_raw_os_error ( errno) ) ;
150
144
}
151
145
Err ( ref e) if e. is_interrupted ( ) => { }
152
146
Err ( e) => {
@@ -175,8 +169,8 @@ impl Command {
175
169
// allowed to exist in dead code), but it sounds bad, so we go out of our
176
170
// way to avoid that all-together.
177
171
#[ 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 ,
172
+ const ERR_APPLE_TV_WATCH_NO_FORK_EXEC : io :: Error = io:: const_io_error!(
173
+ io :: ErrorKind :: Unsupported ,
180
174
"`fork`+`exec`-based process spawning is not supported on this target" ,
181
175
) ;
182
176
@@ -219,7 +213,7 @@ impl Command {
219
213
thread:: sleep ( delay) ;
220
214
} else {
221
215
return Err ( io:: const_io_error!(
222
- ErrorKind :: WouldBlock ,
216
+ io :: ErrorKind :: WouldBlock ,
223
217
"forking returned EBADF too often" ,
224
218
) ) ;
225
219
}
@@ -234,8 +228,8 @@ impl Command {
234
228
pub fn exec ( & mut self , default : Stdio ) -> io:: Error {
235
229
let envp = self . capture_env ( ) ;
236
230
237
- if self . saw_nul ( ) {
238
- return io :: const_io_error! ( ErrorKind :: InvalidInput , "nul byte found in provided data" , ) ;
231
+ if let Err ( err ) = self . validate_input ( ) {
232
+ return err ;
239
233
}
240
234
241
235
match self . setup_io ( default, true ) {
@@ -561,7 +555,7 @@ impl Command {
561
555
thread:: sleep ( delay) ;
562
556
} else {
563
557
return Err ( io:: const_io_error!(
564
- ErrorKind :: WouldBlock ,
558
+ io :: ErrorKind :: WouldBlock ,
565
559
"posix_spawnp returned EBADF too often" ,
566
560
) ) ;
567
561
}
@@ -729,7 +723,7 @@ impl Command {
729
723
// But we cannot obtain its pid even though pidfd_getpid support was verified earlier.
730
724
// This might happen if libc can't open procfs because the file descriptor limit has been reached.
731
725
libc:: close ( pidfd) ;
732
- return Err ( Error :: new (
726
+ return Err ( io :: Error :: new (
733
727
e. kind ( ) ,
734
728
"pidfd_spawnp succeeded but the child's PID could not be obtained" ,
735
729
) ) ;
@@ -1190,7 +1184,6 @@ impl ExitStatusError {
1190
1184
mod linux_child_ext {
1191
1185
1192
1186
use crate :: os:: linux:: process as os;
1193
- use crate :: sys:: pal:: unix:: ErrorKind ;
1194
1187
use crate :: sys:: pal:: unix:: linux:: pidfd as imp;
1195
1188
use crate :: sys_common:: FromInner ;
1196
1189
use crate :: { io, mem} ;
@@ -1203,7 +1196,9 @@ mod linux_child_ext {
1203
1196
. as_ref ( )
1204
1197
// SAFETY: The os type is a transparent wrapper, therefore we can transmute references
1205
1198
. map ( |fd| unsafe { mem:: transmute :: < & imp:: PidFd , & os:: PidFd > ( fd) } )
1206
- . ok_or_else ( || io:: Error :: new ( ErrorKind :: Uncategorized , "No pidfd was created." ) )
1199
+ . ok_or_else ( || {
1200
+ io:: Error :: new ( io:: ErrorKind :: Uncategorized , "No pidfd was created." )
1201
+ } )
1207
1202
}
1208
1203
1209
1204
fn into_pidfd ( mut self ) -> Result < os:: PidFd , Self > {
0 commit comments