diff mbox series

[bug#53063,v2,wip-harden-installer,16/18] installer: Use dynamic-wind to setup installer.

Message ID 20220115135011.5817-17-dev@jpoiret.xyz
State Accepted
Headers show
Series General improvements to the installer | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch fail View Laminar job
cbaines/issue success View issue

Commit Message

Josselin Poiret Jan. 15, 2022, 1:50 p.m. UTC
* gnu/installer.scm (installer-program): Use dynamic-wind, so that
completely uncaught exceptions can be printed properly.
---
 gnu/installer.scm | 92 ++++++++++++++++++++++++-----------------------
 1 file changed, 47 insertions(+), 45 deletions(-)
diff mbox series

Patch

diff --git a/gnu/installer.scm b/gnu/installer.scm
index c7e0921a19..86495a067b 100644
--- a/gnu/installer.scm
+++ b/gnu/installer.scm
@@ -416,51 +416,53 @@  (define installer-builder
 
             (define current-installer newt-installer)
             (define steps (#$steps current-installer))
-            ((installer-init current-installer))
-
-            (parameterize
-                ((run-command-in-installer
-                  (installer-run-command current-installer)))
-              (catch #t
-                (lambda ()
-                  (define results
-                    (run-installer-steps
-                     #:rewind-strategy 'menu
-                     #:menu-proc (installer-menu-page current-installer)
-                     #:steps steps))
-
-                  (match (result-step results 'final)
-                    ('success
-                     ;; We did it!  Let's reboot!
-                     (sync)
-                     (stop-service 'root))
-                    (_
-                     ;; The installation failed, exit so that it is restarted
-                     ;; by login.
-                     #f)))
-                (const #f)
-                (lambda (key . args)
-                  (installer-log-line "crashing due to uncaught exception: ~s ~s"
-                          key args)
-                  (let ((error-file "/tmp/last-installer-error")
-                        (dump-archive "/tmp/dump.tgz"))
-                    (call-with-output-file error-file
-                      (lambda (port)
-                        (display-backtrace (make-stack #t) port)
-                        (print-exception port
-                                         (stack-ref (make-stack #t) 1)
-                                         key args)))
-                    (make-dump dump-archive
-                               #:result %current-result
-                               #:backtrace error-file)
-                    (let ((report
-                           ((installer-dump-page current-installer)
-                            dump-archive)))
-                      ((installer-exit-error current-installer)
-                       error-file report key args)))
-                  (primitive-exit 1))))
-
-            ((installer-exit current-installer))))))
+            (dynamic-wind
+              (installer-init current-installer)
+              
+              (lambda ()
+                (parameterize
+                    ((run-command-in-installer
+                      (installer-run-command current-installer)))
+                  (catch #t
+                    (lambda ()
+                      (define results
+                        (run-installer-steps
+                         #:rewind-strategy 'menu
+                         #:menu-proc (installer-menu-page current-installer)
+                         #:steps steps))
+
+                      (match (result-step results 'final)
+                        ('success
+                         ;; We did it!  Let's reboot!
+                         (sync)
+                         (stop-service 'root))
+                        (_
+                         ;; The installation failed, exit so that it is restarted
+                         ;; by login.
+                         #f)))
+                    (const #f)
+                    (lambda (key . args)
+                      (installer-log-line "crashing due to uncaught exception: ~s ~s"
+                                          key args)
+                      (let ((error-file "/tmp/last-installer-error")
+                            (dump-archive "/tmp/dump.tgz"))
+                        (call-with-output-file error-file
+                          (lambda (port)
+                            (display-backtrace (make-stack #t) port)
+                            (print-exception port
+                                             (stack-ref (make-stack #t) 1)
+                                             key args)))
+                        (make-dump dump-archive
+                                   #:result %current-result
+                                   #:backtrace error-file)
+                        (let ((report
+                               ((installer-dump-page current-installer)
+                                dump-archive)))
+                          ((installer-exit-error current-installer)
+                           error-file report key args)))
+                      (primitive-exit 1)))))
+
+              (installer-exit current-installer))))))
 
   (program-file
    "installer"