Subject: [bug#30948] [PATCH core-updates] guix: Reap finished child processes in build containers.

From: Carlo Zancanaro <[email-masked]>
Date: Tue, 27 Mar 2018 10:39:41 +1100

Okay, it turns out my previous patch was very wrong. I tried to 
start a build and it broke pretty significantly.

I've attached a new patch that at least starts building. My 
computer takes too long to actually build anything, but I'm 
slightly more confident that my change won't break everything.

From c57b2fe19865afc21fd1fd9a7cad3286b05a9b22 Mon Sep 17 00:00:00 2001
From: Carlo Zancanaro <[email-masked]>
Date: Mon, 26 Mar 2018 22:08:26 +1100
Subject: [PATCH] guix: Reap finished child processes in build containers.

* guix/derivations (build-expression->derivation)[prologue]: Handle SIGCHLD
  and reap child processes when they finish.
---
 guix/derivations.scm | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/guix/derivations.scm b/guix/derivations.scm
index da686e89e..27ab3e420 100644
--- a/guix/derivations.scm
+++ b/guix/derivations.scm
@@ -1201,6 +1201,21 @@ ALLOWED-REFERENCES, DISALLOWED-REFERENCES, LOCAL-BUILD?, and SUBSTITUTABLE?."
                                           (else drv))))))
                                inputs))
 
+                      ;; The root process in the build container should reap
+                      ;; processes that die, so handle SIGCHLD.
+                      (use-modules (ice-9 match))
+                      (sigaction SIGCHLD
+                        (lambda _
+                          (let loop ()
+                            (match (catch 'system-error
+                                     (lambda ()
+                                       (waitpid WAIT_ANY WNOHANG))
+                                     (lambda args
+                                       '(0 . -)))
+                              ((0 . _) #f)
+                              ((pid . _) (loop)))))
+                        SA_NOCLDSTOP)
+
                       ,@(if (null? modules)
                             '()
                             ;; Remove our own settings.
-- 
2.16.2