guix-commits
[Top][All Lists]
Advanced

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

01/07: services: shepherd: Leave the finalization thread in peace.


From: guix-commits
Subject: 01/07: services: shepherd: Leave the finalization thread in peace.
Date: Thu, 29 Sep 2022 17:11:00 -0400 (EDT)

civodul pushed a commit to branch master
in repository guix.

commit 168a7933c0e138dc7061a3f0dc96871e16da5c5f
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Thu Sep 29 22:20:18 2022 +0200

    services: shepherd: Leave the finalization thread in peace.
    
    This gets rid of that (in)famous at boot time:
    
      error in finalization thread: Success
    
    This was caused by the file-descriptor closing loop, which would clause
    the finalization pipe, leading the finalization thread to (erroneously)
    error out.
    
    Thanks to Josselin Poiret for locating the problem!
    
    * gnu/services/shepherd.scm (shepherd-boot-gexp): In 'loop', replace
    'close-fdes' with a pair of 'fcntl' calls to add FD_CLOEXEC.
---
 gnu/services/shepherd.scm | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/gnu/services/shepherd.scm b/gnu/services/shepherd.scm
index 61f759a19d..7110e5aa89 100644
--- a/gnu/services/shepherd.scm
+++ b/gnu/services/shepherd.scm
@@ -107,14 +107,15 @@
       (symlink (canonicalize-path "/run/current-system")
                "/run/booted-system")
 
-      ;; Close any remaining open file descriptors to be on the safe
-      ;; side.  This must be the very last thing we do, because
-      ;; Guile has internal FDs such as 'sleep_pipe' that need to be
-      ;; alive.
+      ;; Ensure open file descriptors are close-on-exec so shepherd doesn't
+      ;; inherit them.
       (let loop ((fd 3))
         (when (< fd 1024)
-          (false-if-exception (close-fdes fd))
-          (loop (+ 1 fd))))
+          (false-if-exception
+           (let ((flags (fcntl fd F_GETFD)))
+             (when (zero? (logand flags FD_CLOEXEC))
+               (fcntl fd F_SETFD (logior FD_CLOEXEC flags)))))
+          (loop (+ fd 1))))
 
       ;; Start shepherd.
       (execl #$(file-append shepherd "/bin/shepherd")



reply via email to

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