From 868eb5ecdef294a9e4cf218e907af8f0e822c4e2 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Fri, 19 Jul 2024 17:54:30 +0200 Subject: 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 --- src/libutil/processes.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/libutil/processes.cc') 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) -- cgit v1.2.3