guix-devel
[Top][All Lists]
Advanced

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

[PATCH v2] shepherd: add support for kexec


From: Jakob Kirsch
Subject: [PATCH v2] shepherd: add support for kexec
Date: Thu, 3 Oct 2024 23:01:39 +0200

---
 AUTHORS                             |  1 +
 configure.ac                        |  2 ++
 modules/shepherd/scripts/reboot.scm | 12 ++++++++++--
 modules/shepherd/service.scm        |  9 +++++++++
 modules/shepherd/system.scm.in      |  6 ++++++
 5 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/AUTHORS b/AUTHORS
index 19132a7..6642bdc 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -10,3 +10,4 @@ when it was known as GNU dmd.  Others have since contributed:
              Alex Sassmannshausen <alex.sassmannshausen@gmail.com>
             David Thompson <dthompson2@worcester.edu>
              Andy Wingo <wingo@pobox.com>
+            Jakob Kirsch <jakob.kirsch@web.de>
diff --git a/configure.ac b/configure.ac
index f98024d..cfbd938 100644
--- a/configure.ac
+++ b/configure.ac
@@ -104,6 +104,7 @@ case "$host_os" in
     AC_COMPUTE_INT([RB_DISABLE_CAD], [RB_DISABLE_CAD], [#include 
<sys/reboot.h>])
     AC_COMPUTE_INT([RB_POWER_OFF], [RB_POWER_OFF], [#include <sys/reboot.h>])
     AC_COMPUTE_INT([RB_SW_SUSPEND], [RB_SW_SUSPEND], [#include <sys/reboot.h>])
+    AC_COMPUTE_INT([RB_KEXEC], [RB_KEXEC], [#include <sys/reboot.h>])
     ;;
   gnu*)
     # On GNU/Hurd, the Mach-derived reboot.h uses different names, and
@@ -125,6 +126,7 @@ AC_SUBST([RB_DISABLE_CAD])
 AC_SUBST([RB_AUTOBOOT])
 AC_SUBST([RB_HALT_SYSTEM])
 AC_SUBST([RB_POWER_OFF])
+AC_SUBST([RB_KEXEC])
 AC_MSG_RESULT([done])

 AC_MSG_CHECKING([<sys/prctl.h> constants])
diff --git a/modules/shepherd/scripts/reboot.scm 
b/modules/shepherd/scripts/reboot.scm
index 6be5414..f7f6647 100644
--- a/modules/shepherd/scripts/reboot.scm
+++ b/modules/shepherd/scripts/reboot.scm
@@ -30,6 +30,8 @@
 (define (main . args)
   (initialize-cli)

+  (define reboot-action 'stop)
+
   (parameterize ((program-name "reboot"))
     (let ((socket-file %system-socket-file)
           (command-args '()))
@@ -44,13 +46,19 @@
                       #:argument-name "FILE"
                       #:description "send commands to FILE"
                       #:action (lambda (file)
-                                 (set! socket-file file))))
+                                 (set! socket-file file)))
+                    (option
+                      #:long-name "do-kexec" #:short-name #\k
+                      #:takes-argument? #f
+                      #:description "reboot using kexec"
+                      #:action (lambda () (set! reboot-action 'reboot-kexec))
+                    ))

       (set! command-args (reverse command-args))
       (with-system-error-handling
        (let ((sock (open-connection socket-file)))
          ;; Send the command without further ado.
-         (write-command (shepherd-command 'stop 'root) sock)
+         (write-command (shepherd-command reboot-action 'root) sock)

          ;; Receive output if we're not already dead.
          (match (read sock)
diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index 0a52b7a..f076277 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -2849,6 +2849,15 @@ Clients such as 'herd' can read it and format it in a 
human-readable way."
           (lambda (key)
             (local-output (l10n "Shutting down..."))
             (power-off)))))
+
+     (reboot-kexec
+       "Reboot the system and run kexec."
+       (lambda (running)
+        (catch 'quit
+          (cut stop root-service)
+          (lambda (key)
+            (local-output (l10n "Rebooting with kexec..."))
+            (reboot-kexec)))))
      ;; Evaluate arbitrary code.
      (load
       "Load the Scheme code from FILE into shepherd.  This is potentially
diff --git a/modules/shepherd/system.scm.in b/modules/shepherd/system.scm.in
index 9929f38..bb95455 100644
--- a/modules/shepherd/system.scm.in
+++ b/modules/shepherd/system.scm.in
@@ -26,6 +26,7 @@
   #:use-module (srfi srfi-26)
   #:export (disable-reboot-on-ctrl-alt-del
             reboot
+            reboot-kexec
             halt
             power-off
             max-file-descriptors
@@ -49,6 +50,7 @@
 (define RB_HALT_SYSTEM @RB_HALT_SYSTEM@)
 (define RB_POWER_OFF @RB_POWER_OFF@)
 (define RB_DISABLE_CAD @RB_DISABLE_CAD@)          ; integer | #f
+(define RB_KEXEC @RB_KEXEC@)

 (define (syscall->procedure return-type name argument-types)
   "Return a procedure that wraps the C function NAME using the dynamic FFI,
@@ -93,6 +95,10 @@ ctrlaltdel(8) and see kernel/reboot.c in Linux."
   "Perform a hard reset of the system now.  Return #f on failure."
   (%libc-reboot RB_AUTOBOOT))

+(define (reboot-kexec)
+  "Execute kernel loaded with 'kexec -l' now.  Return #f on failure."
+  (%libc-reboot RB_KEXEC))
+
 (define (halt)
   "Halt the system.  Return #f on failure."
   (%libc-reboot RB_HALT_SYSTEM))
--
2.46.0




reply via email to

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