Skip to content

Commit

Permalink
Fix exit code for swiftc crashes
Browse files Browse the repository at this point in the history
In the case that swiftc crashed, the worker would return that it exited
0. This was because calling WEXITSTATUS when WIFEXITED is not true is
invalid and happened to return 0 in that case. We now handle the case
where swiftc exits from a signal, and return the signal it exited with
instead. There might be some other cases here that we have to handle in
the future, so for now those are failures so we don't return an invalid
value.

Also see bazelbuild/bazel#14543
  • Loading branch information
keith committed Jan 11, 2022
1 parent c8f9395 commit 5fce9c1
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions tools/common/process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,16 @@ int RunSubProcess(const std::vector<std::string> &args,
return wait_status;
}

int exit_status = WEXITSTATUS(status);
if (exit_status != 0) {
return exit_status;
if (WIFEXITED(status)) {
return WEXITSTATUS(status);
}
return 0;

if (WIFSIGNALED(status)) {
return WTERMSIG(status);
}

// Unhandled case, if we hit this we should handle it above.
return 42;
} else {
std::cerr << "Error forking process '" << args[0] << "'. "
<< strerror(status) << "\n";
Expand Down

0 comments on commit 5fce9c1

Please sign in to comment.