guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

01/03: vm: Distinguish between success and failure of the guest code.


From: guix-commits
Subject: 01/03: vm: Distinguish between success and failure of the guest code.
Date: Thu, 26 Mar 2020 18:46:00 -0400 (EDT)

civodul pushed a commit to branch master
in repository guix.

commit be6520e6a58d7f6ee58f4cab76db9d1245410113
Author: Ludovic Courtès <address@hidden>
AuthorDate: Thu Mar 26 23:21:11 2020 +0100

    vm: Distinguish between success and failure of the guest code.
    
    Fixes <https://bugs.gnu.org/34276>.
    Reported by Tobias Geerinckx-Rice <address@hidden>.
    
    * gnu/system/vm.scm (expression->derivation-in-linux-vm)[loader]:
    Produce '/xchg/.exit-status' file upon success.
    * gnu/build/vm.scm (load-in-linux-vm): Check for 'xchg/.exit-status'
    once QEMU has completed and respond accordingly.
---
 gnu/build/vm.scm  | 11 ++++++++++-
 gnu/system/vm.scm | 15 +++++++++------
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/gnu/build/vm.scm b/gnu/build/vm.scm
index 9a9e5bd..79eed48 100644
--- a/gnu/build/vm.scm
+++ b/gnu/build/vm.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès 
<address@hidden>
+;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès 
<address@hidden>
 ;;; Copyright © 2016 Christopher Allan Webber <address@hidden>
 ;;; Copyright © 2016, 2017 Leo Famulari <address@hidden>
 ;;; Copyright © 2017 Mathieu Othacehe <address@hidden>
@@ -183,6 +183,15 @@ the #:references-graphs parameter of 'derivation'."
               '())
           arch-specific-flags))
 
+  (unless (file-exists? "xchg/.exit-status")
+    (error "VM did not produce an exit code"))
+
+  (match (call-with-input-file "xchg/.exit-status" read)
+    (0 #t)
+    (status (error "guest VM code exited with a non-zero status" status)))
+
+  (delete-file "xchg/.exit-status")
+
   ;; When MAKE-DISK-IMAGE? is true, the image is in OUTPUT already.
   (unless make-disk-image?
     (if single-file-output?
diff --git a/gnu/system/vm.scm b/gnu/system/vm.scm
index d1c131e..c6ec25a 100644
--- a/gnu/system/vm.scm
+++ b/gnu/system/vm.scm
@@ -186,12 +186,15 @@ made available under the /xchg CIFS share."
     ;; the initrd.  See example at
     ;; <https://lists.gnu.org/archive/html/guix-devel/2017-10/msg00233.html>.
     (program-file "linux-vm-loader"
-                  ;; When USER-BUILDER succeeds, reboot (indicating a
-                  ;; success), otherwise die, which causes a kernel panic
-                  ;; ("Attempted to kill init!").
-                  #~(if (zero? (system* #$user-builder))
-                        (reboot)
-                        (exit 1))))
+                  ;; Communicate USER-BUILDER's exit status via /xchg so that
+                  ;; the host can distinguish between success, failure, and
+                  ;; kernel panic.
+                  #~(let ((status (system* #$user-builder)))
+                      (call-with-output-file "/xchg/.exit-status"
+                        (lambda (port)
+                          (write status port)))
+                      (sync)
+                      (reboot))))
 
   (let ((initrd (or initrd
                     (base-initrd file-systems



reply via email to

[Prev in Thread] Current Thread [Next in Thread]