handle errors in waitpid

This commit is contained in:
nakst 2022-02-02 22:01:41 +00:00
parent 3c28c5d0f5
commit 5ba1bf512c
1 changed files with 10 additions and 2 deletions

View File

@ -4652,8 +4652,16 @@ int ExternalSystemShellExecute(ExecutionContext *context, Value *returnValue) {
void *SystemShellExecuteWithWorkingDirectoryThread(void *_coroutine) { void *SystemShellExecuteWithWorkingDirectoryThread(void *_coroutine) {
CoroutineState *coroutine = (CoroutineState *) _coroutine; CoroutineState *coroutine = (CoroutineState *) _coroutine;
int status; int status;
Assert(coroutine->externalCoroutineData.i == waitpid(coroutine->externalCoroutineData.i, &status, 0)); pid_t p = waitpid(coroutine->externalCoroutineData.i, &status, 0);
coroutine->externalCoroutineData.i = WEXITSTATUS(status) == 0;
if (p != coroutine->externalCoroutineData.i) {
fprintf(stderr, "waitpid returned %d\n", p);
perror("waitpid failed: ");
coroutine->externalCoroutineData.i = 0;
} else {
coroutine->externalCoroutineData.i = WEXITSTATUS(status) == 0;
}
ExternalCoroutineDone(coroutine); ExternalCoroutineDone(coroutine);
return NULL; return NULL;
} }