diff options
author | Oliver Reiche <oliver.reiche@huawei.com> | 2023-12-19 15:59:56 +0100 |
---|---|---|
committer | Oliver Reiche <oliver.reiche@huawei.com> | 2023-12-19 18:14:02 +0100 |
commit | c3d28a4cc3115644414ddba41d4b7ada5fd74fc2 (patch) | |
tree | f5af297bef9a1a0ade59cf16c6078ad21d5ca7f5 /src/buildtool/system/system_command.hpp | |
parent | c622f5dcde7c9add9d7b6b8787175195d8247882 (diff) | |
download | justbuild-c3d28a4cc3115644414ddba41d4b7ada5fd74fc2.tar.gz |
SystemCommand: Fix handling of child status
Diffstat (limited to 'src/buildtool/system/system_command.hpp')
-rw-r--r-- | src/buildtool/system/system_command.hpp | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/buildtool/system/system_command.hpp b/src/buildtool/system/system_command.hpp index 660d9202..b9145301 100644 --- a/src/buildtool/system/system_command.hpp +++ b/src/buildtool/system/system_command.hpp @@ -201,10 +201,30 @@ class SystemCommand { // wait for child to finish and obtain return value int status{}; - ::waitpid(pid, &status, 0); + std::optional<int> retval{std::nullopt}; + do { + if (::waitpid(pid, &status, 0) == -1) { + // this should never happen + logger_.Emit(LogLevel::Error, + "Waiting for child failed with: {}", + strerror(errno)); + break; + } + + if (WIFEXITED(status)) { // NOLINT(hicpp-signed-bitwise) + retval = WEXITSTATUS(status); // NOLINT(hicpp-signed-bitwise) + } + else if (WIFSIGNALED(status)) { // NOLINT(hicpp-signed-bitwise) + constexpr auto kSignalBit = 128; + auto sig = WTERMSIG(status); // NOLINT(hicpp-signed-bitwise) + retval = kSignalBit + sig; + logger_.Emit( + LogLevel::Debug, "Child got killed by signal {}", sig); + } + // continue waitpid() in case we got STOPSIG from child + } while (not retval); - // NOLINTNEXTLINE(hicpp-signed-bitwise) - return WEXITSTATUS(status); + return retval; } static auto UnwrapStrings(std::vector<std::string>* v) noexcept |