diff options
author | Michael Brown | 2012-07-12 16:28:09 +0200 |
---|---|---|
committer | Michael Brown | 2012-07-12 16:42:29 +0200 |
commit | 5b4958388ded47c93686076e318195393a4c4b9f (patch) | |
tree | 8547d3fbab761f66ed0c1e965db81b96b75656c8 /src/core/exec.c | |
parent | [pxeprefix] Fetch command line (if any) via PXENV_FILE_CMDLINE (diff) | |
download | ipxe-5b4958388ded47c93686076e318195393a4c4b9f.tar.gz ipxe-5b4958388ded47c93686076e318195393a4c4b9f.tar.xz ipxe-5b4958388ded47c93686076e318195393a4c4b9f.zip |
[cmdline] Store exit status of failed command in errno
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/core/exec.c')
-rw-r--r-- | src/core/exec.c | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/src/core/exec.c b/src/core/exec.c index 139cf7a8..5b3d1489 100644 --- a/src/core/exec.c +++ b/src/core/exec.c @@ -59,18 +59,22 @@ static int stop_state; int execv ( const char *command, char * const argv[] ) { struct command *cmd; int argc; + int rc; /* Count number of arguments */ for ( argc = 0 ; argv[argc] ; argc++ ) {} /* An empty command is deemed to do nothing, successfully */ - if ( command == NULL ) - return 0; + if ( command == NULL ) { + rc = 0; + goto done; + } /* Sanity checks */ if ( argc == 0 ) { DBG ( "%s: empty argument list\n", command ); - return -EINVAL; + rc = -EINVAL; + goto done; } /* Reset getopt() library ready for use by the command. This @@ -82,12 +86,24 @@ int execv ( const char *command, char * const argv[] ) { /* Hand off to command implementation */ for_each_table_entry ( cmd, COMMANDS ) { - if ( strcmp ( command, cmd->name ) == 0 ) - return cmd->exec ( argc, ( char ** ) argv ); + if ( strcmp ( command, cmd->name ) == 0 ) { + rc = cmd->exec ( argc, ( char ** ) argv ); + goto done; + } } printf ( "%s: command not found\n", command ); - return -ENOEXEC; + rc = -ENOEXEC; + + done: + /* Store error number, if an error occurred */ + if ( rc ) { + errno = rc; + if ( errno < 0 ) + errno = -errno; + } + + return rc; } /** |