[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
156/376: Use PR_SET_PDEATHSIG to ensure child cleanup
From: |
Ludovic Courtès |
Subject: |
156/376: Use PR_SET_PDEATHSIG to ensure child cleanup |
Date: |
Wed, 28 Jan 2015 22:04:42 +0000 |
civodul pushed a commit to tag 1.8
in repository guix.
commit 809ca33806d75eeabb9c668b124762fb6462e5bc
Author: Eelco Dolstra <address@hidden>
Date: Thu Aug 21 15:31:43 2014 +0200
Use PR_SET_PDEATHSIG to ensure child cleanup
---
src/libutil/util.cc | 11 ++++++++++-
src/libutil/util.hh | 3 ++-
src/nix-daemon/nix-daemon.cc | 2 +-
3 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 8257487..80e017a 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) {
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index f6f5d1b..4f9f742 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -267,7 +267,8 @@ void killUser(uid_t uid);
/* Fork a process that runs the given function, and return the child
pid to the caller. */
-pid_t startProcess(std::function<void()> fun, const string & errorPrefix =
"error: ");
+pid_t startProcess(std::function<void()> fun, bool dieWithParent = true,
+ const string & errorPrefix = "error: ");
/* Run a program and return its stdout in a string (i.e., like the
diff --git a/src/nix-daemon/nix-daemon.cc b/src/nix-daemon/nix-daemon.cc
index 6d166c4..ced356c 100644
--- a/src/nix-daemon/nix-daemon.cc
+++ b/src/nix-daemon/nix-daemon.cc
@@ -779,7 +779,7 @@ static void daemonLoop(char * * argv)
processConnection(trusted);
_exit(0);
- }, "unexpected Nix daemon error: ");
+ }, false, "unexpected Nix daemon error: ");
} catch (Interrupted & e) {
throw;
- 141/376: Filter Nix-specific ANSI escape sequences from stderr, (continued)
- 141/376: Filter Nix-specific ANSI escape sequences from stderr, Ludovic Courtès, 2015/01/28
- 140/376: Make hook shutdown more reliable, Ludovic Courtès, 2015/01/28
- 144/376: Add some color, Ludovic Courtès, 2015/01/28
- 147/376: Handle header file instantiation, Ludovic Courtès, 2015/01/28
- 152/376: Flush std::cout before closing stdout, Ludovic Courtès, 2015/01/28
- 146/376: Install config.h only once, Ludovic Courtès, 2015/01/28
- 148/376: Force template regeneration, Ludovic Courtès, 2015/01/28
- 158/376: fix disappearing bash arguments, Ludovic Courtès, 2015/01/28
- 150/376: Provide reasonable default flags for $LESS, Ludovic Courtès, 2015/01/28
- 149/376: Merge commit '2aa93858afee22e0c32d8f4366970976374091ac', Ludovic Courtès, 2015/01/28
- 156/376: Use PR_SET_PDEATHSIG to ensure child cleanup,
Ludovic Courtès <=
- 155/376: Set a curl timeout on binary cache lookups, Ludovic Courtès, 2015/01/28
- 163/376: Fix manual build, Ludovic Courtès, 2015/01/28
- 159/376: Document the "out" usage in allowedReferences, Ludovic Courtès, 2015/01/28
- 154/376: Use unshare() instead of clone(), Ludovic Courtès, 2015/01/28
- 162/376: Introduce allowedRequisites feature, Ludovic Courtès, 2015/01/28
- 157/376: Fix tests, Ludovic Courtès, 2015/01/28
- 151/376: Use pager for more commands, Ludovic Courtès, 2015/01/28
- 153/376: Fix a segfault in ‘nix-env -qa’, Ludovic Courtès, 2015/01/28
- 164/376: allowedRequisites: Drop stdenv mention, Ludovic Courtès, 2015/01/28
- 160/376: Fix building with Clang, Ludovic Courtès, 2015/01/28