about summary refs log tree commit diff
path: root/src/libutil
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2007-03-19T12·48+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2007-03-19T12·48+0000
commit8ab229ddf2383ec6455836f342539b8c89356f76 (patch)
treebbb5e55e69cd7a665691e7de7755bb9050d0f468 /src/libutil
parentb2b6cf3fc83f0e1625214ae31b0b088a266234bf (diff)
* Terminate build hooks and substitutes with a TERM signal, not a KILL
  signal.  This is necessary because those processes may have joined
  the BDB environment, so they have to be given a chance to clean up.
  (NIX-85)

Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/util.cc16
-rw-r--r--src/libutil/util.hh2
2 files changed, 14 insertions, 4 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 1576e1e8b0..ae5af24920 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -641,6 +641,7 @@ Pid::Pid()
 {
     pid = -1;
     separatePG = false;
+    killSignal = SIGKILL;
 }
 
 
@@ -654,6 +655,7 @@ void Pid::operator =(pid_t pid)
 {
     if (this->pid != pid) kill();
     this->pid = pid;
+    killSignal = SIGKILL; // reset signal to default
 }
 
 
@@ -669,10 +671,10 @@ void Pid::kill()
     
     printMsg(lvlError, format("killing process %1%") % pid);
 
-    /* Send a KILL signal to the child.  If it has its own process
-       group, send the signal to every process in the child process
-       group (which hopefully includes *all* its children). */
-    if (::kill(separatePG ? -pid : pid, SIGKILL) != 0)
+    /* Send the requested signal to the child.  If it has its own
+       process group, send the signal to every process in the child
+       process group (which hopefully includes *all* its children). */
+    if (::kill(separatePG ? -pid : pid, killSignal) != 0)
         printMsg(lvlError, (SysError(format("killing process %1%") % pid).msg()));
 
     /* Wait until the child dies, disregarding the exit status. */
@@ -710,6 +712,12 @@ void Pid::setSeparatePG(bool separatePG)
 }
 
 
+void Pid::setKillSignal(int signal)
+{
+    this->killSignal = signal;
+}
+
+
 void killUser(uid_t uid)
 {
     debug(format("killing all processes running under uid `%1%'") % uid);
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index 3c4629957a..4d284ccfdc 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -213,6 +213,7 @@ class Pid
 {
     pid_t pid;
     bool separatePG;
+    int killSignal;
 public:
     Pid();
     ~Pid();
@@ -221,6 +222,7 @@ public:
     void kill();
     int wait(bool block);
     void setSeparatePG(bool separatePG);
+    void setKillSignal(int signal);
 };