Skip to content

Commit

Permalink
Merge pull request neovim#8737 from dimbleby/overly-general-waitpid
Browse files Browse the repository at this point in the history
Only waitpid() for processes that we care about
  • Loading branch information
jamessan committed Jul 13, 2018
2 parents 392817c + fe913d7 commit 4874214
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions src/nvim/os/pty_process_unix.c
Expand Up @@ -273,26 +273,24 @@ static void chld_handler(uv_signal_t *handle, int signum)
int stat = 0;
int pid;

do {
pid = waitpid(-1, &stat, WNOHANG);
} while (pid < 0 && errno == EINTR);

if (pid <= 0) {
return;
}

Loop *loop = handle->loop->data;

kl_iter(WatcherPtr, loop->children, current) {
Process *proc = (*current)->data;
if (proc->pid == pid) {
if (WIFEXITED(stat)) {
proc->status = WEXITSTATUS(stat);
} else if (WIFSIGNALED(stat)) {
proc->status = WTERMSIG(stat);
}
proc->internal_exit_cb(proc);
break;
do {
pid = waitpid(proc->pid, &stat, WNOHANG);
} while (pid < 0 && errno == EINTR);

if (pid <= 0) {
continue;
}

if (WIFEXITED(stat)) {
proc->status = WEXITSTATUS(stat);
} else if (WIFSIGNALED(stat)) {
proc->status = WTERMSIG(stat);
}
proc->internal_exit_cb(proc);
break;
}
}

0 comments on commit 4874214

Please sign in to comment.