Skip to content

Commit

Permalink
Fixed os.Child.exited() does not work correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
shin1m committed Dec 2, 2023
1 parent 669f896 commit 60a921f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions modules/os.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,12 @@ struct t_child : t_sharable
void f_wait(int a_options)
{
if (!v_pid) return;
while (waitpid(v_pid, &v_status, a_options) == -1) if (errno != EINTR) portable::f_throw_system_error();
while (true) {
auto pid = waitpid(v_pid, &v_status, a_options);
if (pid == v_pid) break;
if (pid != -1) return;
if (errno != EINTR) portable::f_throw_system_error();
}
v_pid = 0;
}

Expand Down Expand Up @@ -162,15 +167,15 @@ struct t_child : t_sharable
return f_owned_or_shared<std::lock_guard>([&]
{
f_wait(WNOHANG);
return WIFEXITED(v_status) ? t_pvalue(WEXITSTATUS(v_status)) : nullptr;
return v_pid == 0 && WIFEXITED(v_status) ? t_pvalue(WEXITSTATUS(v_status)) : nullptr;
});
}
t_pvalue f_signaled()
{
return f_owned_or_shared<std::lock_guard>([&]
{
f_wait(WNOHANG);
return WIFSIGNALED(v_status) ? t_pvalue(WTERMSIG(v_status)) : nullptr;
return v_pid == 0 && WIFSIGNALED(v_status) ? t_pvalue(WTERMSIG(v_status)) : nullptr;
});
}
};
Expand Down

0 comments on commit 60a921f

Please sign in to comment.