Index: lib/Support/Unix/Program.inc =================================================================== --- lib/Support/Unix/Program.inc +++ lib/Support/Unix/Program.inc @@ -21,8 +21,10 @@ #include "llvm/Config/config.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/FileSystem.h" +#include "llvm/Support/ManagedStatic.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/Support/Signals.h" #if HAVE_SYS_STAT_H #include #endif @@ -61,10 +63,14 @@ #endif #endif +#include + namespace llvm { using namespace sys; +static ManagedStatic> ChildPIDs; + ProcessInfo::ProcessInfo() : Pid(0), ReturnCode(0) {} ErrorOr sys::findProgramByName(StringRef Name, @@ -177,6 +183,13 @@ } +static void WaitForChildren(void *) { + if(ChildPIDs.isConstructed()) + for (auto PI : *ChildPIDs) + Wait(PI, 0, true, nullptr); + ChildPIDs->clear(); +} + static bool Execute(ProcessInfo &PI, StringRef Program, const char **args, const char **envp, const StringRef **redirects, unsigned memoryLimit, std::string *ErrMsg) { @@ -187,6 +200,8 @@ return false; } + AddSignalHandler(WaitForChildren, nullptr); + // If this OS has posix_spawn and there is no memory limit being implied, use // posix_spawn. It is more efficient than fork/exec. #ifdef HAVE_POSIX_SPAWN