@@ -150,7 +150,7 @@ impl Command {
150150 match cvt ( syscall:: clone ( 0 ) ) ? {
151151 0 => {
152152 drop ( input) ;
153- let err = self . do_exec ( theirs) ;
153+ let Err ( err) = self . do_exec ( theirs) ;
154154 let errno = err. raw_os_error ( ) . unwrap_or ( syscall:: EINVAL ) as u32 ;
155155 let bytes = [
156156 ( errno >> 24 ) as u8 ,
@@ -218,7 +218,10 @@ impl Command {
218218 }
219219
220220 match self . setup_io ( default, true ) {
221- Ok ( ( _, theirs) ) => unsafe { self . do_exec ( theirs) } ,
221+ Ok ( ( _, theirs) ) => unsafe {
222+ let Err ( e) = self . do_exec ( theirs) ;
223+ e
224+ } ,
222225 Err ( e) => e,
223226 }
224227 }
@@ -253,45 +256,38 @@ impl Command {
253256 // allocation). Instead we just close it manually. This will never
254257 // have the drop glue anyway because this code never returns (the
255258 // child will either exec() or invoke syscall::exit)
256- unsafe fn do_exec ( & mut self , stdio : ChildPipes ) -> io:: Error {
257- macro_rules! t {
258- ( $e: expr) => ( match $e {
259- Ok ( e) => e,
260- Err ( e) => return e,
261- } )
262- }
263-
259+ unsafe fn do_exec ( & mut self , stdio : ChildPipes ) -> Result < !, io:: Error > {
264260 if let Some ( fd) = stdio. stderr . fd ( ) {
265- t ! ( cvt( syscall:: dup2( fd, 2 , & [ ] ) ) ) ;
266- let mut flags = t ! ( cvt( syscall:: fcntl( 2 , syscall:: F_GETFD , 0 ) ) ) ;
261+ cvt ( syscall:: dup2 ( fd, 2 , & [ ] ) ) ? ;
262+ let mut flags = cvt ( syscall:: fcntl ( 2 , syscall:: F_GETFD , 0 ) ) ? ;
267263 flags &= ! syscall:: O_CLOEXEC ;
268- t ! ( cvt( syscall:: fcntl( 2 , syscall:: F_SETFD , flags) ) ) ;
264+ cvt ( syscall:: fcntl ( 2 , syscall:: F_SETFD , flags) ) ? ;
269265 }
270266 if let Some ( fd) = stdio. stdout . fd ( ) {
271- t ! ( cvt( syscall:: dup2( fd, 1 , & [ ] ) ) ) ;
272- let mut flags = t ! ( cvt( syscall:: fcntl( 1 , syscall:: F_GETFD , 0 ) ) ) ;
267+ cvt ( syscall:: dup2 ( fd, 1 , & [ ] ) ) ? ;
268+ let mut flags = cvt ( syscall:: fcntl ( 1 , syscall:: F_GETFD , 0 ) ) ? ;
273269 flags &= ! syscall:: O_CLOEXEC ;
274- t ! ( cvt( syscall:: fcntl( 1 , syscall:: F_SETFD , flags) ) ) ;
270+ cvt ( syscall:: fcntl ( 1 , syscall:: F_SETFD , flags) ) ? ;
275271 }
276272 if let Some ( fd) = stdio. stdin . fd ( ) {
277- t ! ( cvt( syscall:: dup2( fd, 0 , & [ ] ) ) ) ;
278- let mut flags = t ! ( cvt( syscall:: fcntl( 0 , syscall:: F_GETFD , 0 ) ) ) ;
273+ cvt ( syscall:: dup2 ( fd, 0 , & [ ] ) ) ? ;
274+ let mut flags = cvt ( syscall:: fcntl ( 0 , syscall:: F_GETFD , 0 ) ) ? ;
279275 flags &= ! syscall:: O_CLOEXEC ;
280- t ! ( cvt( syscall:: fcntl( 0 , syscall:: F_SETFD , flags) ) ) ;
276+ cvt ( syscall:: fcntl ( 0 , syscall:: F_SETFD , flags) ) ? ;
281277 }
282278
283279 if let Some ( g) = self . gid {
284- t ! ( cvt( syscall:: setregid( g as usize , g as usize ) ) ) ;
280+ cvt ( syscall:: setregid ( g as usize , g as usize ) ) ? ;
285281 }
286282 if let Some ( u) = self . uid {
287- t ! ( cvt( syscall:: setreuid( u as usize , u as usize ) ) ) ;
283+ cvt ( syscall:: setreuid ( u as usize , u as usize ) ) ? ;
288284 }
289285 if let Some ( ref cwd) = self . cwd {
290- t ! ( cvt( syscall:: chdir( cwd) ) ) ;
286+ cvt ( syscall:: chdir ( cwd) ) ? ;
291287 }
292288
293289 for callback in self . closures . iter_mut ( ) {
294- t ! ( callback( ) ) ;
290+ callback ( ) ? ;
295291 }
296292
297293 self . env . apply ( ) ;
@@ -313,9 +309,9 @@ impl Command {
313309 } ;
314310
315311 let mut file = if let Some ( program) = program {
316- t ! ( File :: open( program. as_os_str( ) ) )
312+ File :: open ( program. as_os_str ( ) ) ?
317313 } else {
318- return io:: Error :: from_raw_os_error ( syscall:: ENOENT ) ;
314+ return Err ( io:: Error :: from_raw_os_error ( syscall:: ENOENT ) ) ;
319315 } ;
320316
321317 // Push all the arguments
@@ -327,7 +323,7 @@ impl Command {
327323 let mut shebang = [ 0 ; 2 ] ;
328324 let mut read = 0 ;
329325 loop {
330- match t ! ( reader. read( & mut shebang[ read..] ) ) {
326+ match reader. read ( & mut shebang[ read..] ) ? {
331327 0 => break ,
332328 n => read += n,
333329 }
@@ -338,9 +334,9 @@ impl Command {
338334 // First of all, since we'll be passing another file to
339335 // fexec(), we need to manually check that we have permission
340336 // to execute this file:
341- let uid = t ! ( cvt( syscall:: getuid( ) ) ) ;
342- let gid = t ! ( cvt( syscall:: getgid( ) ) ) ;
343- let meta = t ! ( file. metadata( ) ) ;
337+ let uid = cvt ( syscall:: getuid ( ) ) ? ;
338+ let gid = cvt ( syscall:: getgid ( ) ) ? ;
339+ let meta = file. metadata ( ) ? ;
344340
345341 let mode = if uid == meta. uid ( ) as usize {
346342 meta. mode ( ) >> 3 * 2 & 0o7
@@ -350,12 +346,12 @@ impl Command {
350346 meta. mode ( ) & 0o7
351347 } ;
352348 if mode & 1 == 0 {
353- return io:: Error :: from_raw_os_error ( syscall:: EPERM ) ;
349+ return Err ( io:: Error :: from_raw_os_error ( syscall:: EPERM ) ) ;
354350 }
355351
356352 // Second of all, we need to actually read which interpreter it wants
357353 let mut interpreter = Vec :: new ( ) ;
358- t ! ( reader. read_until( b'\n' , & mut interpreter) ) ;
354+ reader. read_until ( b'\n' , & mut interpreter) ? ;
359355 // Pop one trailing newline, if any
360356 if interpreter. ends_with ( & [ b'\n' ] ) {
361357 interpreter. pop ( ) . unwrap ( ) ;
@@ -373,11 +369,11 @@ impl Command {
373369 } ;
374370 if let Some ( ref interpreter) = interpreter {
375371 let path: & OsStr = OsStr :: from_bytes ( & interpreter) ;
376- file = t ! ( File :: open( path) ) ;
372+ file = File :: open ( path) ? ;
377373
378374 args. push ( [ interpreter. as_ptr ( ) as usize , interpreter. len ( ) ] ) ;
379375 } else {
380- t ! ( file. seek( SeekFrom :: Start ( 0 ) ) ) ;
376+ file. seek ( SeekFrom :: Start ( 0 ) ) ? ;
381377 }
382378
383379 args. push ( [ self . program . as_ptr ( ) as usize , self . program . len ( ) ] ) ;
@@ -396,13 +392,12 @@ impl Command {
396392 }
397393
398394 if let Err ( err) = syscall:: fexec ( file. as_raw_fd ( ) , & args, & vars) {
399- io:: Error :: from_raw_os_error ( err. errno as i32 )
395+ Err ( io:: Error :: from_raw_os_error ( err. errno as i32 ) )
400396 } else {
401397 panic ! ( "return from exec without err" ) ;
402398 }
403399 }
404400
405-
406401 fn setup_io ( & self , default : Stdio , needs_stdin : bool )
407402 -> io:: Result < ( StdioPipes , ChildPipes ) > {
408403 let null = Stdio :: Null ;
0 commit comments