about summary refs log tree commit diff
path: root/src/libutil/util.cc
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-08-21T13·31+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-08-21T13·31+0200
commit809ca33806d75eeabb9c668b124762fb6462e5bc (patch)
tree475f02c052e8bf8e733d18bea4a5d4e5624edcac /src/libutil/util.cc
parent163fdf292e5368e8102f34f246547ba992e5cab4 (diff)
Use PR_SET_PDEATHSIG to ensure child cleanup
Diffstat (limited to 'src/libutil/util.cc')
-rw-r--r--src/libutil/util.cc11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 825748792a..80e017a4f1 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -19,6 +19,10 @@
 #include <sys/syscall.h>
 #endif
 
+#ifdef __linux__
+#include <sys/prctl.h>
+#endif
+
 
 extern char * * environ;
 
@@ -847,7 +851,8 @@ void killUser(uid_t uid)
 //////////////////////////////////////////////////////////////////////
 
 
-pid_t startProcess(std::function<void()> fun, const string & errorPrefix)
+pid_t startProcess(std::function<void()> fun,
+    bool dieWithParent, const string & errorPrefix)
 {
     pid_t pid = fork();
     if (pid == -1) throw SysError("unable to fork");
@@ -855,6 +860,10 @@ pid_t startProcess(std::function<void()> fun, const string & errorPrefix)
     if (pid == 0) {
         _writeToStderr = 0;
         try {
+#if __linux__
+            if (dieWithParent && prctl(PR_SET_PDEATHSIG, SIGKILL) == -1)
+                throw SysError("setting death signal");
+#endif
             restoreAffinity();
             fun();
         } catch (std::exception & e) {