Make Program::Wait provide an error message string for errors

executing the child process and abnormal child process termination.

llvm-svn: 117661
This commit is contained in:
Dan Gohman 2010-10-29 16:39:01 +00:00
parent 8682b69b81
commit cae3c53b31
1 changed files with 19 additions and 9 deletions

View File

@ -350,22 +350,32 @@ Program::Wait(unsigned secondsToWait,
sigaction(SIGALRM, &Old, 0); sigaction(SIGALRM, &Old, 0);
} }
// Return the proper exit status. 0=success, >0 is programs' exit status, // Return the proper exit status. Detect error conditions
// <0 means a signal was returned, -9999999 means the program dumped core. // so we can return -1 for them and set ErrMsg informatively.
int result = 0; int result = 0;
if (WIFEXITED(status)) if (WIFEXITED(status)) {
result = WEXITSTATUS(status); result = WEXITSTATUS(status);
else if (WIFSIGNALED(status)) if (result == 127) {
result = 0 - WTERMSIG(status); *ErrMsg = llvm::sys::StrError(ENOENT);
return -1;
}
if (result == 126) {
*ErrMsg = "Program could not be executed";
return -1;
}
} else if (WIFSIGNALED(status)) {
*ErrMsg = strsignal(WTERMSIG(status));
#ifdef WCOREDUMP #ifdef WCOREDUMP
else if (WCOREDUMP(status)) if (WCOREDUMP(status))
result |= 0x01000000; *ErrMsg += " (core dumped)";
#endif #endif
return -1;
}
return result; return result;
#else #else
return -99; *ErrMsg = "Program::Wait is not implemented on this platform yet!";
return -1;
#endif #endif
} }
bool bool