@@ -1537,7 +1537,8 @@ either LOG-PORT or LOG-FILE if it's true, whereas file descriptor 0 (standard
input) points to INPUT-PORT or /dev/null.
EXTRA-PORTS are made available starting from file descriptor 3 onwards; all
-other file descriptors are closed prior to yielding control to COMMAND. When
+other file descriptors are closed prior to yielding control to COMMAND, unless
+EXTRA-PORTS is #t, in which case no file descriptors are closed. When
CREATE-SESSION? is true, call 'setsid' first.
Guile's SETRLIMIT procedure is applied on the entries in RESOURCE-LIMITS. For
@@ -1590,7 +1591,17 @@ false."
(reconfigure-fds (cons* stdin
stdout
stderr
- extra-ports)))
+ (if (list? extra-ports)
+ extra-ports
+ '())))
+ (unless (eq? extra-ports #t)
+ (let ((max-fds-count (max-file-descriptors)))
+ (let loop ((fd (+ 3 (length extra-ports))))
+ (when (< fd max-fds-count)
+ ;; Use FD_CLOEXEC instead of close-fdes so fd finalizers don't
+ ;; run.
+ (catch-system-error (fcntl fd F_SETFD FD_CLOEXEC))
+ (loop (+ fd 1)))))))
;; setgid must be done *before* setuid, otherwise the user will
;; likely no longer have permissions to setgid.