[PATCH] Processes that spawn other processes should wait for their children to exit before exiting due to a signal.
Chris Bieneman
beanz at apple.com
Thu Apr 30 15:05:36 PDT 2015
Hi ddunbar,
If a process that spawns other processes (like the clang driver) gets killed via a SIGINT, it should wait until its children exit before returning from the signal handler. This prevents the child processes from getting re-parented, which causes problems for build systems that are the parent of clang processes.
http://reviews.llvm.org/D9420
Files:
lib/Support/Unix/Program.inc
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 <sys/stat.h>
#endif
@@ -61,10 +63,14 @@
#endif
#endif
+#include <vector>
+
namespace llvm {
using namespace sys;
+static ManagedStatic<std::vector<ProcessInfo>> ChildPIDs;
+
ProcessInfo::ProcessInfo() : Pid(0), ReturnCode(0) {}
ErrorOr<std::string> 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
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9420.24774.patch
Type: text/x-patch
Size: 1442 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150430/afcf572d/attachment.bin>
More information about the llvm-commits
mailing list