@@ -378,6 +378,7 @@ impl Command {
378
378
callback ( ) ?;
379
379
}
380
380
381
+ let mut _reset = None ;
381
382
if let Some ( envp) = maybe_envp
382
383
&& self . get_resolve_in_parent_path ( )
383
384
&& self . env_saw_path ( )
@@ -390,8 +391,9 @@ impl Command {
390
391
program : & CStr ,
391
392
args : & CStringArray ,
392
393
envp : & CStringArray ,
393
- ) -> libc:: c_int {
394
- unsafe { libc:: execvpe ( program. as_ptr ( ) , args. as_ptr ( ) , envp. as_ptr ( ) ) }
394
+ ) -> io:: Error {
395
+ unsafe { libc:: execvpe ( program. as_ptr ( ) , args. as_ptr ( ) , envp. as_ptr ( ) ) } ;
396
+ io:: Error :: last_os_error ( )
395
397
}
396
398
397
399
// ...so if we're not gnu then use our own implementation.
@@ -400,7 +402,7 @@ impl Command {
400
402
program : & CStr ,
401
403
args : & CStringArray ,
402
404
envp : & CStringArray ,
403
- ) -> libc :: c_int {
405
+ ) -> io :: Error {
404
406
unsafe {
405
407
let name = program. to_bytes ( ) ;
406
408
let mut buffer =
@@ -433,18 +435,18 @@ impl Command {
433
435
}
434
436
environ = environ. add ( 1 ) ;
435
437
}
436
- // If execve is successful then it'll never return, thus we'll never reach this point.
437
- -1
438
+ // If execve is successful then it'll never return,
439
+ // thus we only reach this point on failure..
440
+ io:: Error :: from_raw_os_error ( libc:: ENOENT )
438
441
}
439
442
}
440
- exec_with_env ( self . get_program_cstr ( ) , self . get_argv ( ) , envp) ;
443
+ return Err ( exec_with_env ( self . get_program_cstr ( ) , self . get_argv ( ) , envp) ) ;
441
444
} else if let Some ( envp) = maybe_envp {
442
445
// Although we're performing an exec here we may also return with an
443
446
// error from this function (without actually exec'ing) in which case we
444
447
// want to be sure to restore the global environment back to what it
445
448
// once was, ensuring that our temporary override, when free'd, doesn't
446
449
// corrupt our process's environment.
447
- let mut _reset = None ;
448
450
struct Reset ( * const * const libc:: c_char ) ;
449
451
450
452
impl Drop for Reset {
@@ -457,8 +459,8 @@ impl Command {
457
459
458
460
_reset = Some ( Reset ( * sys:: env:: environ ( ) ) ) ;
459
461
* sys:: env:: environ ( ) = envp. as_ptr ( ) ;
460
- libc:: execvp ( self . get_program_cstr ( ) . as_ptr ( ) , self . get_argv ( ) . as_ptr ( ) ) ;
461
462
}
463
+ libc:: execvp ( self . get_program_cstr ( ) . as_ptr ( ) , self . get_argv ( ) . as_ptr ( ) ) ;
462
464
Err ( io:: Error :: last_os_error ( ) )
463
465
}
464
466
0 commit comments