libutil: make RunningProgram::wait more resilient

this will usually be used either directly (which is always fine) or in
Finally blocks (where it must never throw execptions). make sure that,
exceptions being handled or not, the calling wait() in Finally doesn't
cause crashes due to the Finally no-nested-exceptions-thrown assertion

Change-Id: Ib83a5d9483b1fe83b9a957dcefeefce5d088f06d
This commit is contained in:
eldritch horrors 2024-07-19 17:54:30 +02:00
parent c907d805bf
commit 868eb5ecde

View file

@ -280,9 +280,14 @@ RunningProgram::~RunningProgram()
void RunningProgram::wait() void RunningProgram::wait()
{ {
if (std::uncaught_exceptions() == 0) {
int status = pid.wait(); int status = pid.wait();
if (status) if (status)
throw ExecError(status, "program '%1%' %2%", program, statusToString(status)); throw ExecError(status, "program '%1%' %2%", program, statusToString(status));
} else {
pid.kill();
debug("killed subprocess %1% during exception handling", program);
}
} }
RunningProgram runProgram2(const RunOptions & options) RunningProgram runProgram2(const RunOptions & options)