Subject: [PATCH wip-harden-installer 06/14] installer: Disable automatic finalization for child thread.

From: Josselin Poiret <[email-masked]>
Date: Thu, 6 Jan 2022 23:48:04 +0100

* gnu/installer/utils.scm (run-external-command-with-handler): Disable
finalization manually, to avoid having the finalizer thread spout
"error in finalization thread: Success".
---
 gnu/installer/utils.scm | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/gnu/installer/utils.scm b/gnu/installer/utils.scm
index 878434f074..ad220492d9 100644
--- a/gnu/installer/utils.scm
+++ b/gnu/installer/utils.scm
@@ -32,6 +32,8 @@ (define-module (gnu installer utils)
   #:use-module (ice-9 regex)
   #:use-module (ice-9 format)
   #:use-module (ice-9 textual-ports)
+  #:use-module (system foreign)
+  #:use-module (system foreign-library)
   #:export (read-lines
             read-all
             nearest-exact-integer
@@ -143,6 +145,14 @@ (define* (run-external-command-with-handler handler command)
     (match (primitive-fork)
       (0 ;; We're in the child
        (close-port input)
+       ;; XXX: Disable automatic finalization because we're going to exec.
+       ;; Might become unnecessary with newer Guile versions, as the
+       ;; *possible* finalization thread may stop properly when its pipe is
+       ;; closed.
+       ((foreign-library-function (load-foreign-library #f)
+                                  "scm_set_automatic_finalization_enabled"
+                                  #:return-type int
+                                  #:arg-types (list int)) 0)
        (reset-fds
         (open-fdes "/dev/null" O_WRONLY)
         ;; Avoid port GC'ing closing the fd by increasing its revealed count.
-- 
2.34.0