Update exec_shell command to return the exit code.

This commit is contained in:
DragonMinded 2016-01-30 19:13:42 +00:00
parent ee63cb41d2
commit d4c2ffce68
2 changed files with 28 additions and 5 deletions

View File

@ -81,17 +81,40 @@ void verbose_printf( const char * const fmt, ... )
}
}
void exec_shell( const char * shellcmd )
int exec_shell( const char * shellcmd )
{
if( fork() == 0 )
int status = 0;
pid_t pid;
if( (pid = fork()) == 0 )
{
/* Try to execute, return sentinal if failed */
execl("/bin/bash","/bin/bash","-c",shellcmd,NULL);
_exit(127);
}
else
{
int status;
wait(&status);
if( waitpid( pid, &status, 0 ) > 0 )
{
if (WIFEXITED(status) && !WEXITSTATUS(status))
{
/* Successfully completed */
status = 0;
}
else if (WIFEXITED(status) && WEXITSTATUS(status))
{
/* Get exit code */
status = WEXITSTATUS(status);
}
}
else
{
/* Couldn't get program */
status = 127;
}
}
return status;
}
void PrintHex( const char * prepend, const unsigned char * const data, int length )

View File

@ -11,7 +11,7 @@
#define DVD_TYPE_TOSHIBA_SD_B100_DVD 3
void verbose_printf( const char * const fmt, ... );
void exec_shell( const char * shellcmd );
int exec_shell( const char * shellcmd );
void PrintHex( const char * prepend, const unsigned char * const data, int length );
#endif