guix-commits
[Top][All Lists]
Advanced

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

[shepherd] 02/02: service: Shut down finalization thread before closing


From: Ludovic Courtès
Subject: [shepherd] 02/02: service: Shut down finalization thread before closing file descriptors.
Date: Sun, 19 Apr 2020 16:40:46 -0400 (EDT)

civodul pushed a commit to branch master
in repository shepherd.

commit b966a898553b5d7a1fa6b30f4b9da7394b7652ab
Author: Ludovic Courtès <address@hidden>
AuthorDate: Sun Apr 19 22:36:04 2020 +0200

    service: Shut down finalization thread before closing file descriptors.
    
    This addresses the infamous:
    
      error in the finalization thread: Bad file descriptor
    
    messages that we've been seeing since Guile 2.2.
    
    * modules/shepherd/service.scm (exec-command): Wrap 'loop' in
    'without-automatic-finalization'.  Remove inner loop over (fdes->ports i).
---
 modules/shepherd/service.scm | 41 +++++++++++++++++------------------------
 1 file changed, 17 insertions(+), 24 deletions(-)

diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index 86bcbe5..64b0664 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -851,30 +851,23 @@ false."
      (when file-creation-mask
        (umask file-creation-mask))
 
-     ;; As the last action, close file descriptors.  Doing it last makes
-     ;; "error in the finalization thread: Bad file descriptor" issues
-     ;; unlikely on 2.2.
-     (let loop ((i 3))
-       (when (< i max-fd)
-         ;; First try to close any ports associated with file descriptor I.
-         ;; Otherwise the finalization thread might get around to closing
-         ;; those ports eventually, which will raise an EBADF exception (on
-         ;; 2.2), leading to messages like "error in the finalization
-         ;; thread: Bad file descriptor".
-         (for-each (lambda (port)
-                     (catch-system-error (close-port port)))
-                   (fdes->ports i))
-         (catch-system-error (close-fdes i))
-         (loop (+ i 1)))))
-
-     (catch 'system-error
-       (lambda ()
-         (apply execlp program program args))
-       (lambda args
-         (format (current-error-port)
-                 "exec of ~s failed: ~a~%"
-                 program (strerror (system-error-errno args)))
-         (primitive-exit 1))))))
+     ;; Last, close all file descriptors.  Do that after shutting down the
+     ;; finalization thread since we will close its pipe, leading to
+     ;; "error in the finalization thread: Bad file descriptor".
+     (without-automatic-finalization
+      (let loop ((i 3))
+        (when (< i max-fd)
+          (catch-system-error (close-fdes i))
+          (loop (+ i 1))))
+
+      (catch 'system-error
+        (lambda ()
+          (apply execlp program program args))
+        (lambda args
+          (format (current-error-port)
+                  "exec of ~s failed: ~a~%"
+                  program (strerror (system-error-errno args)))
+          (primitive-exit 1))))))))
 
 (define* (fork+exec-command command
                             #:key



reply via email to

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