bp::child->wait_for does not give correct err code

boost::process::child->wait_for does not give the error code
from the process being run. Re-arrange the code to work-around
it.
This commit is contained in:
sramamoorthy 2019-05-07 13:35:28 -07:00 committed by Alex Miller
parent f27a40f118
commit b56d8e648f
1 changed files with 14 additions and 20 deletions

View File

@ -102,33 +102,27 @@ ACTOR Future<int> spawnProcess(std::string binPath, std::vector<std::string> par
if (!isSync && !g_network->isSimulated()) {
while (c.running() && runTime <= maxWaitTime) {
wait(delay(0.1));
runTime += 0.1;
}
if (c.running()) {
c.terminate();
err = -1;
} else {
err = c.exit_code();
wait(delay(0.1));
runTime += 0.1;
}
} else {
int maxWaitTimeInt = static_cast<int>(maxWaitTime + 1.0);
c.wait_for(std::chrono::seconds(maxWaitTimeInt));
}
if (c.running()) {
TraceEvent(SevWarnAlways, "ChildTermination")
.detail("Cmd", binPath)
.detail("Args", argsString);
c.terminate();
err = -1;
if (!c.wait_for(std::chrono::seconds(1))) {
TraceEvent(SevWarnAlways, "SpawnProcessFailedToExit")
.detail("Cmd", binPath)
.detail("Args", argsString);
}
} else {
state std::error_code errCode;
bool succ = c.wait_for(std::chrono::seconds(3), errCode);
err = errCode.value();
if (!succ) {
err = -1;
c.terminate();
if (!c.wait_for(std::chrono::seconds(1))) {
TraceEvent(SevWarnAlways, "SpawnProcessFailedToExit")
.detail("Cmd", binPath)
.detail("Args", argsString);
}
}
err = c.exit_code();
}
TraceEvent("SpawnProcess")
.detail("Cmd", binPath)