guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[shepherd] 01/01: Lazily register SIGCHLD hander on first call to 'fork+


From: Ludovic Courtès
Subject: [shepherd] 01/01: Lazily register SIGCHLD hander on first call to 'fork+exec-command'.
Date: Thu, 7 Sep 2017 10:49:57 -0400 (EDT)

civodul pushed a commit to branch master
in repository shepherd.

commit f776de04e6702e18d95152072e78c43441d3ccc3
Author: Jelle Licht <address@hidden>
Date:   Thu Sep 7 00:52:49 2017 +0200

    Lazily register SIGCHLD hander on first call to 'fork+exec-command'.
    
    * modules/shepherd.scm (main): Move unconditional top-level call to 
'sigaction' to...
    * modules/shepherd/service.scm (fork+exec-command): here. Use new variable.
    (%sigchld-handler-installed?): New variable.
    
    Signed-off-by: Ludovic Courtès <address@hidden>
---
 modules/shepherd.scm         | 3 ---
 modules/shepherd/service.scm | 7 +++++++
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/modules/shepherd.scm b/modules/shepherd.scm
index f7c169d..7ea6493 100644
--- a/modules/shepherd.scm
+++ b/modules/shepherd.scm
@@ -142,9 +142,6 @@
     ;; Start the 'root' service.
     (start root-service)
 
-    ;; Install the SIGCHLD handler.
-    (sigaction SIGCHLD respawn-service SA_NOCLDSTOP)
-
     ;; This _must_ succeed.  (We could also put the `catch' around
     ;; `main', but it is often useful to get the backtrace, and
     ;; `caught-error' does not do this yet.)
diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index 72fbc3d..b2d8bc5 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -100,6 +100,9 @@
 
             condition->sexp))
 
+;; Keep track of lazy initialization of SIGCHLD handler
+(define %sigchld-handler-installed? #f)
+
 ;; Type of service actions.
 (define-record-type <action>
   (make-action name proc doc)
@@ -787,6 +790,10 @@ false."
                              (default-environment-variables)))
   "Spawn a process that executed COMMAND as per 'exec-command', and return
 its PID."
+  ;; Install the SIGCHLD handler if this is the first fork+exec-command call
+  (unless %sigchld-handler-installed?
+    (sigaction SIGCHLD respawn-service SA_NOCLDSTOP)
+    (set! %sigchld-handler-installed? #t))
   (let ((pid (primitive-fork)))
     (if (zero? pid)
         (exec-command command



reply via email to

[Prev in Thread] Current Thread [Next in Thread]