2
0
mirror of https://github.com/xcat2/xNBA.git synced 2024-11-29 12:49:49 +00:00

[cmdline] Store exit status of failed command in errno

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown 2012-07-12 15:28:09 +01:00
parent e84e19d4ed
commit 5b4958388d

View File

@ -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;
}
/**