@@ -150,7 +150,7 @@ impl Command {
150
150
match cvt ( syscall:: clone ( 0 ) ) ? {
151
151
0 => {
152
152
drop ( input) ;
153
- let err = self . do_exec ( theirs) ;
153
+ let Err ( err) = self . do_exec ( theirs) ;
154
154
let errno = err. raw_os_error ( ) . unwrap_or ( syscall:: EINVAL ) as u32 ;
155
155
let bytes = [
156
156
( errno >> 24 ) as u8 ,
@@ -218,7 +218,10 @@ impl Command {
218
218
}
219
219
220
220
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
+ } ,
222
225
Err ( e) => e,
223
226
}
224
227
}
@@ -253,45 +256,38 @@ impl Command {
253
256
// allocation). Instead we just close it manually. This will never
254
257
// have the drop glue anyway because this code never returns (the
255
258
// 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 > {
264
260
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 ) ) ? ;
267
263
flags &= ! syscall:: O_CLOEXEC ;
268
- t ! ( cvt( syscall:: fcntl( 2 , syscall:: F_SETFD , flags) ) ) ;
264
+ cvt ( syscall:: fcntl ( 2 , syscall:: F_SETFD , flags) ) ? ;
269
265
}
270
266
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 ) ) ? ;
273
269
flags &= ! syscall:: O_CLOEXEC ;
274
- t ! ( cvt( syscall:: fcntl( 1 , syscall:: F_SETFD , flags) ) ) ;
270
+ cvt ( syscall:: fcntl ( 1 , syscall:: F_SETFD , flags) ) ? ;
275
271
}
276
272
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 ) ) ? ;
279
275
flags &= ! syscall:: O_CLOEXEC ;
280
- t ! ( cvt( syscall:: fcntl( 0 , syscall:: F_SETFD , flags) ) ) ;
276
+ cvt ( syscall:: fcntl ( 0 , syscall:: F_SETFD , flags) ) ? ;
281
277
}
282
278
283
279
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 ) ) ? ;
285
281
}
286
282
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 ) ) ? ;
288
284
}
289
285
if let Some ( ref cwd) = self . cwd {
290
- t ! ( cvt( syscall:: chdir( cwd) ) ) ;
286
+ cvt ( syscall:: chdir ( cwd) ) ? ;
291
287
}
292
288
293
289
for callback in self . closures . iter_mut ( ) {
294
- t ! ( callback( ) ) ;
290
+ callback ( ) ? ;
295
291
}
296
292
297
293
self . env . apply ( ) ;
@@ -313,9 +309,9 @@ impl Command {
313
309
} ;
314
310
315
311
let mut file = if let Some ( program) = program {
316
- t ! ( File :: open( program. as_os_str( ) ) )
312
+ File :: open ( program. as_os_str ( ) ) ?
317
313
} else {
318
- return io:: Error :: from_raw_os_error ( syscall:: ENOENT ) ;
314
+ return Err ( io:: Error :: from_raw_os_error ( syscall:: ENOENT ) ) ;
319
315
} ;
320
316
321
317
// Push all the arguments
@@ -327,7 +323,7 @@ impl Command {
327
323
let mut shebang = [ 0 ; 2 ] ;
328
324
let mut read = 0 ;
329
325
loop {
330
- match t ! ( reader. read( & mut shebang[ read..] ) ) {
326
+ match reader. read ( & mut shebang[ read..] ) ? {
331
327
0 => break ,
332
328
n => read += n,
333
329
}
@@ -338,9 +334,9 @@ impl Command {
338
334
// First of all, since we'll be passing another file to
339
335
// fexec(), we need to manually check that we have permission
340
336
// 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 ( ) ? ;
344
340
345
341
let mode = if uid == meta. uid ( ) as usize {
346
342
meta. mode ( ) >> 3 * 2 & 0o7
@@ -350,12 +346,12 @@ impl Command {
350
346
meta. mode ( ) & 0o7
351
347
} ;
352
348
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 ) ) ;
354
350
}
355
351
356
352
// Second of all, we need to actually read which interpreter it wants
357
353
let mut interpreter = Vec :: new ( ) ;
358
- t ! ( reader. read_until( b'\n' , & mut interpreter) ) ;
354
+ reader. read_until ( b'\n' , & mut interpreter) ? ;
359
355
// Pop one trailing newline, if any
360
356
if interpreter. ends_with ( & [ b'\n' ] ) {
361
357
interpreter. pop ( ) . unwrap ( ) ;
@@ -373,11 +369,11 @@ impl Command {
373
369
} ;
374
370
if let Some ( ref interpreter) = interpreter {
375
371
let path: & OsStr = OsStr :: from_bytes ( & interpreter) ;
376
- file = t ! ( File :: open( path) ) ;
372
+ file = File :: open ( path) ? ;
377
373
378
374
args. push ( [ interpreter. as_ptr ( ) as usize , interpreter. len ( ) ] ) ;
379
375
} else {
380
- t ! ( file. seek( SeekFrom :: Start ( 0 ) ) ) ;
376
+ file. seek ( SeekFrom :: Start ( 0 ) ) ? ;
381
377
}
382
378
383
379
args. push ( [ self . program . as_ptr ( ) as usize , self . program . len ( ) ] ) ;
@@ -396,13 +392,12 @@ impl Command {
396
392
}
397
393
398
394
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 ) )
400
396
} else {
401
397
panic ! ( "return from exec without err" ) ;
402
398
}
403
399
}
404
400
405
-
406
401
fn setup_io ( & self , default : Stdio , needs_stdin : bool )
407
402
-> io:: Result < ( StdioPipes , ChildPipes ) > {
408
403
let null = Stdio :: Null ;
0 commit comments