[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[shepherd] 02/04: service: 'exec-command' closes file descriptors as its
From: |
Ludovic Courtès |
Subject: |
[shepherd] 02/04: service: 'exec-command' closes file descriptors as its last action. |
Date: |
Thu, 22 Mar 2018 06:24:42 -0400 (EDT) |
civodul pushed a commit to branch master
in repository shepherd.
commit c412b8875aff230e51678fec5606cb895562b947
Author: Ludovic Courtès <address@hidden>
Date: Thu Mar 22 11:00:09 2018 +0100
service: 'exec-command' closes file descriptors as its last action.
* modules/shepherd/service.scm (exec-command): Move
file-descriptor-closing loop as the last action before 'execl'.
---
modules/shepherd/service.scm | 29 ++++++++++++++++-------------
1 file changed, 16 insertions(+), 13 deletions(-)
diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index 056483a..7b062a1 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -745,19 +745,6 @@ false."
(print-exception (current-error-port) #f key args)
(primitive-exit 1))))
- (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)))))
-
;; setgid must be done *before* setuid, otherwise the user will
;; likely no longer have permissions to setgid.
(when group
@@ -782,6 +769,22 @@ false."
(print-exception (current-error-port) #f key args)
(primitive-exit 1))))
+ ;; 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))