From 894b79227dc9451e39c7e01216198e70f1b3cb07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 3 Dec 2020 18:06:18 +0100 Subject: [PATCH] Revert "Revert "fixed excessive spawning of child processes / fixed potential zombie processes (#2924)"" This reverts commit 5650897a4b37623ff1662652d3c4f3d9d7a77e59. --- cli/threadexecutor.cpp | 43 ++++++++++++++++++++++++++---------------- cli/threadexecutor.h | 6 ++++++ 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/cli/threadexecutor.cpp b/cli/threadexecutor.cpp index d447b2c55..0ac8de7c2 100644 --- a/cli/threadexecutor.cpp +++ b/cli/threadexecutor.cpp @@ -182,7 +182,7 @@ unsigned int ThreadExecutor::check() std::list::const_iterator iFileSettings = mSettings.project.fileSettings.begin(); for (;;) { // Start a new child - size_t nchildren = rpipes.size(); + size_t nchildren = childFile.size(); if ((iFile != mFiles.end() || iFileSettings != mSettings.project.fileSettings.end()) && nchildren < mSettings.jobs && checkLoadAverage(nchildren)) { int pipes[2]; if (pipe(pipes) == -1) { @@ -284,7 +284,7 @@ unsigned int ThreadExecutor::check() ++rp; } } - + } else if (!childFile.empty()) { int stat = 0; pid_t child = waitpid(0, &stat, WNOHANG); if (child > 0) { @@ -295,21 +295,17 @@ unsigned int ThreadExecutor::check() childFile.erase(c); } - if (WIFSIGNALED(stat)) { + if (WIFEXITED(stat)) { + const int exitstaus = WEXITSTATUS(stat); + if (exitstaus != 0) { + std::ostringstream oss; + oss << "Child process exited with " << exitstaus; + reportInternalChildErr(childname, oss.str()); + } + } else if (WIFSIGNALED(stat)) { std::ostringstream oss; - oss << "Internal error: Child process crashed with signal " << WTERMSIG(stat); - - std::list locations; - locations.emplace_back(childname, 0, 0); - const ErrorMessage errmsg(locations, - emptyString, - Severity::error, - oss.str(), - "cppcheckError", - false); - - if (!mSettings.nomsg.isSuppressed(errmsg.toSuppressionsErrorMessage())) - mErrorLogger.reportErr(errmsg); + oss << "Child process crashed with signal " << WTERMSIG(stat); + reportInternalChildErr(childname, oss.str()); } } } else { @@ -359,6 +355,21 @@ void ThreadExecutor::bughuntingReport(const std::string &str) writeToPipe(REPORT_VERIFICATION, str.c_str()); } +void ThreadExecutor::reportInternalChildErr(const std::string &childname, const std::string &msg) +{ + std::list locations; + locations.emplace_back(childname, 0, 0); + const ErrorMessage errmsg(locations, + emptyString, + Severity::error, + "Internal error: " + msg, + "cppcheckError", + false); + + if (!mSettings.nomsg.isSuppressed(errmsg.toSuppressionsErrorMessage())) + mErrorLogger.reportErr(errmsg); +} + #elif defined(THREADING_MODEL_WIN) void ThreadExecutor::addFileContent(const std::string &path, const std::string &content) diff --git a/cli/threadexecutor.h b/cli/threadexecutor.h index 888450873..e6b244ad8 100644 --- a/cli/threadexecutor.h +++ b/cli/threadexecutor.h @@ -102,6 +102,12 @@ private: */ bool checkLoadAverage(size_t nchildren); + /** + * @brief Reports internal errors related to child processes + * @param msg The error message + */ + void reportInternalChildErr(const std::string &childname, const std::string &msg); + public: /** * @return true if support for threads exist.