diff options
author | eldritch horrors <pennae@lix.systems> | 2024-07-19 17:54:30 +0200 |
---|---|---|
committer | eldritch horrors <pennae@lix.systems> | 2024-08-02 13:12:44 +0000 |
commit | 868eb5ecdef294a9e4cf218e907af8f0e822c4e2 (patch) | |
tree | 42876c3ee2944048d30493f31d5215f8db7830e5 /src/libutil/processes.cc | |
parent | c907d805bf733562aee97f1c3d77743351036c67 (diff) |
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
Diffstat (limited to 'src/libutil/processes.cc')
-rw-r--r-- | src/libutil/processes.cc | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/libutil/processes.cc b/src/libutil/processes.cc index 05b1321e9..866ba9647 100644 --- a/src/libutil/processes.cc +++ b/src/libutil/processes.cc @@ -280,9 +280,14 @@ RunningProgram::~RunningProgram() void RunningProgram::wait() { - int status = pid.wait(); - if (status) - throw ExecError(status, "program '%1%' %2%", program, statusToString(status)); + if (std::uncaught_exceptions() == 0) { + int status = pid.wait(); + if (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) |