Fix process polling exit code

This commit is contained in:
2025-08-11 18:27:02 +02:00
parent 955d92bcc7
commit 1276c565da
3 changed files with 20 additions and 33 deletions

View File

@@ -356,7 +356,6 @@ Process SpawnProcess(String command_line, String working_dir, String write_stdin
}
process.is_valid = true;
plat->child_stdout_read = stdout_desc[PIPE_READ];
plat->stdin_write = stdin_desc[PIPE_WRITE];
@@ -365,8 +364,7 @@ Process SpawnProcess(String command_line, String working_dir, String write_stdin
CloseStdin(&process);
}
process.is_valid = true;
return process;
}
@@ -377,12 +375,14 @@ bool IsValid(Process *process) {
}
int status = 0;
pid_t result = waitpid(plat->pid, &status, WNOHANG);
if (result >= 0) {
if (WIFSIGNALED(status) || WIFEXITED(status)) {
process->exit_code = WEXITSTATUS(status);
return false;
}
pollfd p = {};
p.fd = plat->child_stdout_read;
p.events = POLLRDHUP | POLLERR | POLLHUP | POLLNVAL;
int res = poll(&p, 1, 0);
if (res > 0) {
pid_t result = waitpid(plat->pid, &status, 0);
process->exit_code = WEXITSTATUS(status);
return false;
}
return true;
@@ -406,7 +406,7 @@ String PollStdout(Allocator allocator, Process *process, bool force_read) {
p.fd = plat->child_stdout_read;
p.events = POLLIN;
int res = poll(&p, 1, 0);
if (res == 1 || force_read) {
if (res > 0 || force_read) {
result.len = read(plat->child_stdout_read, result.data, 4 * 4096);
}
return result;