From patchwork Thu Jan 6 22:48:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josselin Poiret X-Patchwork-Id: 36060 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 1330A27BBEA; Thu, 6 Jan 2022 22:51:54 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FROM_SUSPICIOUS_NTLD,MAILING_LIST_MULTI,PDS_OTHER_BAD_TLD, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 7974727BBE9 for ; Thu, 6 Jan 2022 22:51:53 +0000 (GMT) Received: from localhost ([::1]:48990 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n5bbs-000337-N9 for patchwork@mira.cbaines.net; Thu, 06 Jan 2022 17:51:52 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57576) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n5bZB-0007SO-7Q for guix-patches@gnu.org; Thu, 06 Jan 2022 17:49:05 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:49729) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n5bZA-00075M-Tx for guix-patches@gnu.org; Thu, 06 Jan 2022 17:49:04 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1n5bZA-00005o-Qu for guix-patches@gnu.org; Thu, 06 Jan 2022 17:49:04 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#53063] [PATCH wip-harden-installer 07/14] installer: Add installer-specific run command process. Resent-From: Josselin Poiret Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 06 Jan 2022 22:49:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 53063 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 53063@debbugs.gnu.org Cc: Josselin Poiret Received: via spool by 53063-submit@debbugs.gnu.org id=B53063.164150932332680 (code B ref 53063); Thu, 06 Jan 2022 22:49:04 +0000 Received: (at 53063) by debbugs.gnu.org; 6 Jan 2022 22:48:43 +0000 Received: from localhost ([127.0.0.1]:42608 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n5bYo-0008Uu-W8 for submit@debbugs.gnu.org; Thu, 06 Jan 2022 17:48:43 -0500 Received: from jpoiret.xyz ([206.189.101.64]:36298) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n5bYk-0008Tn-P2 for 53063@debbugs.gnu.org; Thu, 06 Jan 2022 17:48:39 -0500 Received: from authenticated-user (jpoiret.xyz [206.189.101.64]) by jpoiret.xyz (Postfix) with ESMTPA id 1E66D184F80; Thu, 6 Jan 2022 22:48:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpoiret.xyz; s=dkim; t=1641509318; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WJYviSEmx19L8tH8Ns3DbwYJN+8TuGW4D4ApQPwmiRg=; b=TJOYGFeRxowuc+qiywgxo5g2Se1k44R5md5tiMFUXpx6wSJ/P3a0MmPo0IKLT8HF8x5d2I wVhtZJ62JUNTMKcAKEDcYP+AakEDpSv5jOLLL499+qaI5WHWQHK+OQxJsJQt4kAZZGaVwt ffZu/Vn3NSH23xVnqHZVW8mTyaGDeo+bxJCGK3Tpq+wcLD2gHS2OeI51Hft4Ekk6v9b4cg hFqquB2KkYAwVKTM2zl1cP/ey9beOyEDWmCnSMJqAijStxrXLBLY/tF1zmx6hCD2FPbJgN lY5uh+ILuyIjRWjkFUHH/8pJ/UUw0iuoh1mNu02d3RJNNW6EqITWHpIYvSO2ng== Date: Thu, 6 Jan 2022 23:48:05 +0100 Message-Id: <90da18d18c8398a5278b4893faa81323b0f3cd23.1641507696.git.dev@jpoiret.xyz> In-Reply-To: References: MIME-Version: 1.0 X-Spamd-Bar: / Authentication-Results: jpoiret.xyz; auth=pass smtp.auth=jpoiret@jpoiret.xyz smtp.mailfrom=dev@jpoiret.xyz X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" Reply-to: Josselin Poiret X-ACL-Warn: , Josselin Poiret via Guix-patches X-Patchwork-Original-From: Josselin Poiret via Guix-patches via From: Josselin Poiret X-getmail-retrieved-from-mailbox: Patches * gnu/installer/record.scm (installer)[run-command]: Add field. * gnu/installer/utils.scm (run-command-in-installer): Add parameter. * gnu/installer.scm (installer-program): Parameterize run-command-in-installer with current installer's run-command. * gnu/installer/newt.scm (newt-run-command): New variable. (newt-installer): Use it. --- gnu/installer.scm | 79 +++++++++++++++++++++------------------- gnu/installer/newt.scm | 10 ++++- gnu/installer/record.scm | 7 +++- gnu/installer/utils.scm | 10 +++++ 4 files changed, 65 insertions(+), 41 deletions(-) diff --git a/gnu/installer.scm b/gnu/installer.scm index d0d012f04b..3cc5c79d4e 100644 --- a/gnu/installer.scm +++ b/gnu/installer.scm @@ -416,44 +416,47 @@ (define current-installer newt-installer) (define steps (#$steps current-installer)) ((installer-init 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))) + (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)))))) diff --git a/gnu/installer/newt.scm b/gnu/installer/newt.scm index 61fb9cf2ca..fc851339d1 100644 --- a/gnu/installer/newt.scm +++ b/gnu/installer/newt.scm @@ -79,6 +79,13 @@ (define (exit-error file report key args) (newt-finish) (clear-screen)) +(define (newt-run-command . args) + (newt-suspend) + (clear-screen) + (define result (run-command args)) + (newt-resume) + result) + (define (final-page result prev-steps) (run-final-page result prev-steps)) @@ -150,4 +157,5 @@ (define newt-installer (welcome-page welcome-page) (parameters-menu parameters-menu) (parameters-page parameters-page) - (dump-page dump-page))) + (dump-page dump-page) + (run-command newt-run-command))) diff --git a/gnu/installer/record.scm b/gnu/installer/record.scm index e7cd45ee83..23db3edd70 100644 --- a/gnu/installer/record.scm +++ b/gnu/installer/record.scm @@ -42,7 +42,8 @@ (define-module (gnu installer record) installer-welcome-page installer-parameters-menu installer-parameters-page - installer-dump-page)) + installer-dump-page + installer-run-command)) ;;; @@ -94,4 +95,6 @@ (define-record-type* ;; procedure (keyboard-layout-selection) -> void (parameters-page installer-parameters-page) ;; procedure (dump) -> void - (dump-page installer-dump-page)) + (dump-page installer-dump-page) + ;; procedure command -> bool + (run-command installer-run-command)) diff --git a/gnu/installer/utils.scm b/gnu/installer/utils.scm index ad220492d9..b148fc2a81 100644 --- a/gnu/installer/utils.scm +++ b/gnu/installer/utils.scm @@ -25,6 +25,7 @@ (define-module (gnu installer utils) #:use-module (srfi srfi-1) #:use-module (srfi srfi-19) #:use-module (srfi srfi-34) + #:use-module (srfi srfi-35) #:use-module (ice-9 control) #:use-module (ice-9 match) #:use-module (ice-9 popen) @@ -39,6 +40,7 @@ (define-module (gnu installer utils) nearest-exact-integer read-percentage run-command + run-command-in-installer syslog-port %syslog-line-hook @@ -234,6 +236,14 @@ (define succeeded? (pause) succeeded?) +(define run-command-in-installer + (make-parameter + (lambda (. args) + (raise + (condition + (&serious) + (&message (message "run-command-in-installer not set"))))))) + ;;; ;;; Logging.