[systemd-devel] [PATCH] systemctl: refuse to do kexec, if no kernel is loaded

harald at redhat.com harald at redhat.com
Tue Mar 18 06:14:15 PDT 2014


From: Harald Hoyer <harald at redhat.com>

Doing a kexec with no kernel loaded would currently issue a normal reboot.
This might not be wanted, if the goal of kexec is to circumvent the boot
loader. Better fail to kexec, than to reboot into a maybe broken setup.
---
 src/systemctl/systemctl.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 5a5681b..ac99f44 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -2853,6 +2853,11 @@ static int start_special(sd_bus *bus, char **args) {
                 return -EPERM;
         }
 
+        if (a == ACTION_KEXEC && !kexec_loaded()) {
+                log_error("No kernel loaded for kexec!");
+                return -EINVAL;
+        }
+
         if (arg_force >= 2 &&
             (a == ACTION_HALT ||
              a == ACTION_POWEROFF ||
@@ -6711,6 +6716,12 @@ int main(int argc, char*argv[]) {
                 goto finish;
         }
 
+        if (arg_action == ACTION_KEXEC && !kexec_loaded()) {
+                log_error("No kernel loaded for kexec!");
+                r = -EINVAL;
+                goto finish;
+        }
+
         if (!avoid_bus())
                 r = bus_open_transport_systemd(arg_transport, arg_host, arg_scope != UNIT_FILE_SYSTEM, &bus);
 
-- 
1.8.5.3



More information about the systemd-devel mailing list