From 83df9d4e2402bbe2ea82ee783d1318d66f171c93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sat, 16 Dec 2023 09:48:33 +0100 Subject: [PATCH] fix exit status reporting when evaluation fails --- src/nix-eval-jobs.cc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/nix-eval-jobs.cc b/src/nix-eval-jobs.cc index 704afe1..7e9cf38 100644 --- a/src/nix-eval-jobs.cc +++ b/src/nix-eval-jobs.cc @@ -109,7 +109,8 @@ void handleBrokenWorkerPipe(Proc &proc) { // need to wait for it again to avoid error messages pid_t pid = proc.pid.release(); while (1) { - int rc = waitpid(pid, nullptr, WNOHANG); + int status; + int rc = waitpid(pid, &status, WNOHANG); if (rc == 0) { kill(pid, SIGKILL); throw Error("BUG: worker pipe closed but worker still running?"); @@ -118,16 +119,16 @@ void handleBrokenWorkerPipe(Proc &proc) { throw Error("BUG: waitpid waiting for worker failed: %s", strerror(errno)); } else { - if (WIFEXITED(rc)) { + if (WIFEXITED(status)) { throw Error("evaluation worker exited with %d", - WEXITSTATUS(rc)); - } else if (WIFSIGNALED(rc)) { - if (WTERMSIG(rc) == SIGKILL) { + WEXITSTATUS(status)); + } else if (WIFSIGNALED(status)) { + if (WTERMSIG(status) == SIGKILL) { throw Error("evaluation worker killed by SIGKILL, maybe " "memory limit reached?"); } - throw Error("evaluation worker killed by signal %d", - WTERMSIG(rc)); + throw Error("evaluation worker killed by signal %d (%s)", + WTERMSIG(status), strsignal(WTERMSIG(status))); } // else ignore WIFSTOPPED and WIFCONTINUED } }