Fix process polling exit code
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -458,16 +458,16 @@ function OnSave(buffer_id)
|
||||
end
|
||||
|
||||
function IsCodeExclude(s, meta)
|
||||
if s:match("/.git$") or s:match("\\.git$") or
|
||||
s:match(".exe$") or
|
||||
s:match(".bin$") or
|
||||
s:match(".obj$") or
|
||||
s:match(".o$") or
|
||||
s:match(".lib$") or
|
||||
s:match(".ilk$") or
|
||||
s:match(".cache$") or
|
||||
s:match(".exp$") or
|
||||
s:match(".pdb$") or
|
||||
if s:match("/%.git$") or s:match("\\%.git$") or
|
||||
s:match("%.exe$") or
|
||||
s:match("%.bin$") or
|
||||
s:match("%.obj$") or
|
||||
s:match("%.o$") or
|
||||
s:match("%.lib$") or
|
||||
s:match("%.ilk$") or
|
||||
s:match("%.cache$") or
|
||||
s:match("%.exp$") or
|
||||
s:match("%.pdb$") or
|
||||
s:match("/external/") or s:match("\\external\\")
|
||||
then
|
||||
return false
|
||||
|
||||
@@ -16,9 +16,6 @@ struct UnixProcess {
|
||||
// the appropriate handles. This happens in this case when git grep calls
|
||||
// 'less' program which errors out and doesn't print anything
|
||||
// @todo: maybe I should ask someone smarter about this!
|
||||
|
||||
|
||||
// @todo: rework to fit both linux and windows!
|
||||
void UpdateProcesses() {
|
||||
IterRemove(ActiveProcesses) {
|
||||
IterRemovePrepare(ActiveProcesses);
|
||||
@@ -30,16 +27,6 @@ void UpdateProcesses() {
|
||||
Command_Append(view, poll, it.scroll_to_end);
|
||||
}
|
||||
if (!IsValid(&it)) {
|
||||
for (;;) {
|
||||
String poll = PollStdout(scratch, &it, true);
|
||||
if (poll.len) {
|
||||
Command_Append(view, poll, it.scroll_to_end);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
printf("exit code = %d\n", it.exit_code);
|
||||
remove_item = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user