summaryrefslogtreecommitdiff
path: root/gnu
diff options
context:
space:
mode:
authorMathieu Othacehe <othacehe@gnu.org>2021-12-29 13:45:26 +0100
committerMathieu Othacehe <othacehe@gnu.org>2022-02-02 16:46:42 +0100
commit0d37a5df7e709cadca97cfbbf9c680dfe54b8302 (patch)
treef9b5877771fe70c92d7b7db327419dc2c6fd7c76 /gnu
parent8f585083277e64ea1e9a0848ef3c49f12327618c (diff)
installer: Add crash dump upload support.
Suggested-by: Josselin Poiret <dev@jpoiret.xyz> * gnu/installer/dump.scm: New file. * gnu/installer/newt/dump.scm: New file. * gnu/local.mk (INSTALLER_MODULES): Add them. * gnu/installer/record.scm (<installer>)[dump-page]: New field. * gnu/installer/steps.scm (%current-result): New variable. (run-installer-steps): Update it. * gnu/installer.scm (installer-program): Add tar and gip to the installer path. Add guile-webutils and gnutls to the Guile extensions. Generate and send the crash dump report. * gnu/installer/newt.scm (exit-error): Add a report argument. Display the report id. (dump-page): New procedure. (newt-installer): Update it.
Diffstat (limited to 'gnu')
-rw-r--r--gnu/installer.scm20
-rw-r--r--gnu/installer/dump.scm103
-rw-r--r--gnu/installer/newt.scm18
-rw-r--r--gnu/installer/newt/dump.scm36
-rw-r--r--gnu/installer/record.scm7
-rw-r--r--gnu/installer/steps.scm9
-rw-r--r--gnu/local.mk2
7 files changed, 183 insertions, 12 deletions
diff --git a/gnu/installer.scm b/gnu/installer.scm
index c8b7a66cfc8..d57b1d673a5 100644
--- a/gnu/installer.scm
+++ b/gnu/installer.scm
@@ -33,6 +33,7 @@
33 #:use-module (gnu packages admin) 33 #:use-module (gnu packages admin)
34 #:use-module (gnu packages base) 34 #:use-module (gnu packages base)
35 #:use-module (gnu packages bash) 35 #:use-module (gnu packages bash)
36 #:use-module (gnu packages compression)
36 #:use-module (gnu packages connman) 37 #:use-module (gnu packages connman)
37 #:use-module (gnu packages cryptsetup) 38 #:use-module (gnu packages cryptsetup)
38 #:use-module (gnu packages disk) 39 #:use-module (gnu packages disk)
@@ -336,6 +337,8 @@ selected keymap."
336 guix ;guix system init call 337 guix ;guix system init call
337 util-linux ;mkwap 338 util-linux ;mkwap
338 shadow 339 shadow
340 tar ;dump
341 gzip ;dump
339 coreutils))) 342 coreutils)))
340 (with-output-to-port (%make-void-port "w") 343 (with-output-to-port (%make-void-port "w")
341 (lambda () 344 (lambda ()
@@ -352,7 +355,8 @@ selected keymap."
352 ;; packages …), etc. modules. 355 ;; packages …), etc. modules.
353 (with-extensions (list guile-gcrypt guile-newt 356 (with-extensions (list guile-gcrypt guile-newt
354 guile-parted guile-bytestructures 357 guile-parted guile-bytestructures
355 guile-json-3 guile-git guix gnutls) 358 guile-json-3 guile-git guile-webutils
359 guix gnutls)
356 (with-imported-modules `(,@(source-module-closure 360 (with-imported-modules `(,@(source-module-closure
357 `(,@modules 361 `(,@modules
358 (gnu services herd) 362 (gnu services herd)
@@ -363,6 +367,7 @@ selected keymap."
363 (use-modules (gnu installer record) 367 (use-modules (gnu installer record)
364 (gnu installer keymap) 368 (gnu installer keymap)
365 (gnu installer steps) 369 (gnu installer steps)
370 (gnu installer dump)
366 (gnu installer final) 371 (gnu installer final)
367 (gnu installer hostname) 372 (gnu installer hostname)
368 (gnu installer locale) 373 (gnu installer locale)
@@ -432,15 +437,22 @@ selected keymap."
432 (lambda (key . args) 437 (lambda (key . args)
433 (syslog "crashing due to uncaught exception: ~s ~s~%" 438 (syslog "crashing due to uncaught exception: ~s ~s~%"
434 key args) 439 key args)
435 (let ((error-file "/tmp/last-installer-error")) 440 (let ((error-file "/tmp/last-installer-error")
441 (dump-archive "/tmp/dump.tgz"))
436 (call-with-output-file error-file 442 (call-with-output-file error-file
437 (lambda (port) 443 (lambda (port)
438 (display-backtrace (make-stack #t) port) 444 (display-backtrace (make-stack #t) port)
439 (print-exception port 445 (print-exception port
440 (stack-ref (make-stack #t) 1) 446 (stack-ref (make-stack #t) 1)
441 key args))) 447 key args)))
442 ((installer-exit-error current-installer) 448 (make-dump dump-archive
443 error-file key args)) 449 #:result %current-result
450 #:backtrace error-file)
451 (let ((report
452 ((installer-dump-page current-installer)
453 dump-archive)))
454 ((installer-exit-error current-installer)
455 error-file report key args)))
444 (primitive-exit 1))) 456 (primitive-exit 1)))
445 457
446 ((installer-exit current-installer))))))) 458 ((installer-exit current-installer)))))))
diff --git a/gnu/installer/dump.scm b/gnu/installer/dump.scm
new file mode 100644
index 00000000000..49c40a26afd
--- /dev/null
+++ b/gnu/installer/dump.scm
@@ -0,0 +1,103 @@
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2021 Mathieu Othacehe <othacehe@gnu.org>
3;;;
4;;; This file is part of GNU Guix.
5;;;
6;;; GNU Guix is free software; you can redistribute it and/or modify it
7;;; under the terms of the GNU General Public License as published by
8;;; the Free Software Foundation; either version 3 of the License, or (at
9;;; your option) any later version.
10;;;
11;;; GNU Guix is distributed in the hope that it will be useful, but
12;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19(define-module (gnu installer dump)
20 #:use-module (gnu installer utils)
21 #:use-module (guix build utils)
22 #:use-module (srfi srfi-11)
23 #:use-module (ice-9 iconv)
24 #:use-module (ice-9 match)
25 #:use-module (ice-9 popen)
26 #:use-module (ice-9 textual-ports)
27 #:use-module (web client)
28 #:use-module (web http)
29 #:use-module (web response)
30 #:use-module (webutils multipart)
31 #:export (make-dump
32 send-dump-report))
33
34;; The installer crash dump type.
35(define %dump-type "installer-dump")
36
37(define (result->list result)
38 "Return the alist for the given RESULT."
39 (hash-map->list (lambda (k v)
40 (cons k v))
41 result))
42
43(define* (make-dump output
44 #:key
45 result
46 backtrace)
47 "Create a crash dump archive in OUTPUT. RESULT is the installer result hash
48table. BACKTRACE is the installer Guile backtrace."
49 (let ((dump-dir "/tmp/dump"))
50 (mkdir-p dump-dir)
51 (with-directory-excursion dump-dir
52 ;; backtrace
53 (copy-file backtrace "installer-backtrace")
54
55 ;; installer result
56 (call-with-output-file "installer-result"
57 (lambda (port)
58 (write (result->list result) port)))
59
60 ;; syslog
61 (copy-file "/var/log/messages" "syslog")
62
63 ;; dmesg
64 (let ((pipe (open-pipe* OPEN_READ "dmesg")))
65 (call-with-output-file "dmesg"
66 (lambda (port)
67 (dump-port pipe port)
68 (close-pipe pipe)))))
69
70 (with-directory-excursion (dirname dump-dir)
71 (system* "tar" "-zcf" output (basename dump-dir)))))
72
73(define* (send-dump-report dump
74 #:key
75 (url "https://dump.guix.gnu.org"))
76 "Turn the DUMP archive into a multipart body and send it to the Guix crash
77dump server at URL."
78 (define (match-boundary kont)
79 (match-lambda
80 (('boundary . (? string? b))
81 (kont b))
82 (x #f)))
83
84 (define (response->string response)
85 (bytevector->string
86 (read-response-body response)
87 "UTF-8"))
88
89 (let-values (((body boundary)
90 (call-with-input-file dump
91 (lambda (port)
92 (format-multipart-body
93 `((,%dump-type . ,port)))))))
94 (false-if-exception
95 (response->string
96 (http-post
97 (string-append url "/upload")
98 #:keep-alive? #t
99 #:streaming? #t
100 #:headers `((content-type
101 . (multipart/form-data
102 (boundary . ,boundary))))
103 #:body body)))))
diff --git a/gnu/installer/newt.scm b/gnu/installer/newt.scm
index 4f7fc6f4dcc..d48e2c01298 100644
--- a/gnu/installer/newt.scm
+++ b/gnu/installer/newt.scm
@@ -19,6 +19,7 @@
19(define-module (gnu installer newt) 19(define-module (gnu installer newt)
20 #:use-module (gnu installer record) 20 #:use-module (gnu installer record)
21 #:use-module (gnu installer utils) 21 #:use-module (gnu installer utils)
22 #:use-module (gnu installer newt dump)
22 #:use-module (gnu installer newt ethernet) 23 #:use-module (gnu installer newt ethernet)
23 #:use-module (gnu installer newt final) 24 #:use-module (gnu installer newt final)
24 #:use-module (gnu installer newt parameters) 25 #:use-module (gnu installer newt parameters)
@@ -55,16 +56,19 @@
55 (newt-finish) 56 (newt-finish)
56 (clear-screen)) 57 (clear-screen))
57 58
58(define (exit-error file key args) 59(define (exit-error file report key args)
59 (newt-set-color COLORSET-ROOT "white" "red") 60 (newt-set-color COLORSET-ROOT "white" "red")
60 (let ((width (nearest-exact-integer 61 (let ((width (nearest-exact-integer
61 (* (screen-columns) 0.8))) 62 (* (screen-columns) 0.8)))
62 (height (nearest-exact-integer 63 (height (nearest-exact-integer
63 (* (screen-rows) 0.7)))) 64 (* (screen-rows) 0.7)))
65 (report (if report
66 (format #f ". It has been uploaded as ~a" report)
67 "")))
64 (run-file-textbox-page 68 (run-file-textbox-page
65 #:info-text (format #f (G_ "The installer has encountered an unexpected \ 69 #:info-text (format #f (G_ "The installer has encountered an unexpected \
66problem. The backtrace is displayed below. Please report it by email to \ 70problem. The backtrace is displayed below~a. Please report it by email to \
67<~a>.") %guix-bug-report-address) 71<~a>.") report %guix-bug-report-address)
68 #:title (G_ "Unexpected problem") 72 #:title (G_ "Unexpected problem")
69 #:file file 73 #:file file
70 #:exit-button? #f 74 #:exit-button? #f
@@ -123,6 +127,9 @@ problem. The backtrace is displayed below. Please report it by email to \
123(define (parameters-page keyboard-layout-selection) 127(define (parameters-page keyboard-layout-selection)
124 (run-parameters-page keyboard-layout-selection)) 128 (run-parameters-page keyboard-layout-selection))
125 129
130(define (dump-page steps)
131 (run-dump-page steps))
132
126(define newt-installer 133(define newt-installer
127 (installer 134 (installer
128 (name 'newt) 135 (name 'newt)
@@ -142,4 +149,5 @@ problem. The backtrace is displayed below. Please report it by email to \
142 (services-page services-page) 149 (services-page services-page)
143 (welcome-page welcome-page) 150 (welcome-page welcome-page)
144 (parameters-menu parameters-menu) 151 (parameters-menu parameters-menu)
145 (parameters-page parameters-page))) 152 (parameters-page parameters-page)
153 (dump-page dump-page)))
diff --git a/gnu/installer/newt/dump.scm b/gnu/installer/newt/dump.scm
new file mode 100644
index 00000000000..64f0d582377
--- /dev/null
+++ b/gnu/installer/newt/dump.scm
@@ -0,0 +1,36 @@
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2021 Mathieu Othacehe <othacehe@gnu.org>
3;;;
4;;; This file is part of GNU Guix.
5;;;
6;;; GNU Guix is free software; you can redistribute it and/or modify it
7;;; under the terms of the GNU General Public License as published by
8;;; the Free Software Foundation; either version 3 of the License, or (at
9;;; your option) any later version.
10;;;
11;;; GNU Guix is distributed in the hope that it will be useful, but
12;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19(define-module (gnu installer newt dump)
20 #:use-module (gnu installer dump)
21 #:use-module (gnu installer newt page)
22 #:use-module (guix i18n)
23 #:use-module (newt)
24 #:export (run-dump-page))
25
26(define (run-dump-page dump)
27 "Run a dump page, proposing the user to upload the crash dump to Guix
28servers."
29 (case (choice-window
30 (G_ "Crash dump upload")
31 (G_ "Yes")
32 (G_ "No")
33 (G_ "The installer failed. Do you accept to upload the crash dump \
34to Guix servers, so that we can investigate the issue?"))
35 ((1) (send-dump-report dump))
36 ((2) #f)))
diff --git a/gnu/installer/record.scm b/gnu/installer/record.scm
index 0b34318c457..e7cd45ee83e 100644
--- a/gnu/installer/record.scm
+++ b/gnu/installer/record.scm
@@ -41,7 +41,8 @@
41 installer-services-page 41 installer-services-page
42 installer-welcome-page 42 installer-welcome-page
43 installer-parameters-menu 43 installer-parameters-menu
44 installer-parameters-page)) 44 installer-parameters-page
45 installer-dump-page))
45 46
46 47
47;;; 48;;;
@@ -91,4 +92,6 @@
91 ;; procedure (menu-proc) -> void 92 ;; procedure (menu-proc) -> void
92 (parameters-menu installer-parameters-menu) 93 (parameters-menu installer-parameters-menu)
93 ;; procedure (keyboard-layout-selection) -> void 94 ;; procedure (keyboard-layout-selection) -> void
94 (parameters-page installer-parameters-page)) 95 (parameters-page installer-parameters-page)
96 ;; procedure (dump) -> void
97 (dump-page installer-dump-page))
diff --git a/gnu/installer/steps.scm b/gnu/installer/steps.scm
index c05dfa567a8..55433cff31a 100644
--- a/gnu/installer/steps.scm
+++ b/gnu/installer/steps.scm
@@ -52,7 +52,13 @@
52 %installer-configuration-file 52 %installer-configuration-file
53 %installer-target-dir 53 %installer-target-dir
54 format-configuration 54 format-configuration
55 configuration->file)) 55 configuration->file
56
57 %current-result))
58
59;; Hash table storing the step results. Use it only for logging and debug
60;; purposes.
61(define %current-result (make-hash-table))
56 62
57;; This condition may be raised to abort the current step. 63;; This condition may be raised to abort the current step.
58(define-condition-type &installer-step-abort &condition 64(define-condition-type &installer-step-abort &condition
@@ -183,6 +189,7 @@ return the accumalated result so far."
183 (let* ((id (installer-step-id step)) 189 (let* ((id (installer-step-id step))
184 (compute (installer-step-compute step)) 190 (compute (installer-step-compute step))
185 (res (compute result done-steps))) 191 (res (compute result done-steps)))
192 (hash-set! %current-result id res)
186 (run (alist-cons id res result) 193 (run (alist-cons id res result)
187 #:todo-steps rest-steps 194 #:todo-steps rest-steps
188 #:done-steps (append done-steps (list step)))))))) 195 #:done-steps (append done-steps (list step))))))))
diff --git a/gnu/local.mk b/gnu/local.mk
index 9969bc67cb3..9510c796717 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -758,6 +758,7 @@ GNU_SYSTEM_MODULES = \
758INSTALLER_MODULES = \ 758INSTALLER_MODULES = \
759 %D%/installer.scm \ 759 %D%/installer.scm \
760 %D%/installer/connman.scm \ 760 %D%/installer/connman.scm \
761 %D%/installer/dump.scm \
761 %D%/installer/final.scm \ 762 %D%/installer/final.scm \
762 %D%/installer/hostname.scm \ 763 %D%/installer/hostname.scm \
763 %D%/installer/keymap.scm \ 764 %D%/installer/keymap.scm \
@@ -774,6 +775,7 @@ INSTALLER_MODULES = \
774 %D%/installer/user.scm \ 775 %D%/installer/user.scm \
775 %D%/installer/utils.scm \ 776 %D%/installer/utils.scm \
776 \ 777 \
778 %D%/installer/newt/dump.scm \
777 %D%/installer/newt/ethernet.scm \ 779 %D%/installer/newt/ethernet.scm \
778 %D%/installer/newt/final.scm \ 780 %D%/installer/newt/final.scm \
779 %D%/installer/newt/parameters.scm \ 781 %D%/installer/newt/parameters.scm \