forked from lix-project/nix-eval-jobs
release proc.pid properly before calling waitpid()
This commit is contained in:
parent
e1ad62cef1
commit
521380076d
|
@ -1,4 +1,5 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <sys/signal.h>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
@ -85,23 +86,23 @@ struct State {
|
||||||
};
|
};
|
||||||
|
|
||||||
void handleBrokenWorkerPipe(Proc &proc) {
|
void handleBrokenWorkerPipe(Proc &proc) {
|
||||||
while (1) {
|
// we already took the process status from Proc, no
|
||||||
int rc = waitpid(proc.pid, nullptr, WNOHANG);
|
|
||||||
if (rc == 0) {
|
|
||||||
proc.pid = -1; // we already took the process status from Proc, no
|
|
||||||
// need to wait for it again to avoid error messages
|
// need to wait for it again to avoid error messages
|
||||||
|
pid_t pid = proc.pid.release();
|
||||||
|
while (1) {
|
||||||
|
int rc = waitpid(pid, nullptr, WNOHANG);
|
||||||
|
if (rc == 0) {
|
||||||
|
kill(pid, SIGKILL);
|
||||||
throw Error("BUG: worker pipe closed but worker still running?");
|
throw Error("BUG: worker pipe closed but worker still running?");
|
||||||
} else if (rc == -1) {
|
} else if (rc == -1) {
|
||||||
proc.pid = -1;
|
kill(pid, SIGKILL);
|
||||||
throw Error("BUG: waitpid waiting for worker failed: %s",
|
throw Error("BUG: waitpid waiting for worker failed: %s",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
} else {
|
} else {
|
||||||
if (WIFEXITED(rc)) {
|
if (WIFEXITED(rc)) {
|
||||||
proc.pid = -1;
|
|
||||||
throw Error("evaluation worker exited with %d",
|
throw Error("evaluation worker exited with %d",
|
||||||
WEXITSTATUS(rc));
|
WEXITSTATUS(rc));
|
||||||
} else if (WIFSIGNALED(rc)) {
|
} else if (WIFSIGNALED(rc)) {
|
||||||
proc.pid = -1;
|
|
||||||
if (WTERMSIG(rc) == SIGKILL) {
|
if (WTERMSIG(rc) == SIGKILL) {
|
||||||
throw Error("evaluation worker killed by SIGKILL, maybe "
|
throw Error("evaluation worker killed by SIGKILL, maybe "
|
||||||
"memory limit reached?");
|
"memory limit reached?");
|
||||||
|
|
Loading…
Reference in a new issue