Skip to contentSkip to conversation

emu/linux: work around systemctl kexec returning

PATCH In review Robbie Harwood 2 participants 2 messages Mar 23, 2023 – Mar 28, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 emu/linux: work around systemctl kexec returning

Per systemctl(1), it "is asynchronous; it will return after the reboot operation is enqueued, without waiting for it to complete". This differs from kexec(8), which calls reboot(2) and therefore does not return.

When not using fallback, this confusingly results in:

error trying to perform 'systemctl kexec': 0
Aborted. Press any key to exit.

on screen for a bit, followed by successful kexec.

To reduce the liklihood of hitting this case, add a delay on succesful return. Ultimately, the systemd interface is racy: we can't avoid it entirely unless we never fallback on success.

---
 grub-core/loader/emu/linux.c | 4 ++++
 1 file changed, 4 insertions(+)
grub-core/loader/emu/linux.c +4 -0
index 0cf378a376..7de3f7f861 100644
@@ -74,6 +74,10 @@ grub_linux_boot (void)
 		(kexecute==1) ? "do-or-die" : "just-in-case");
   rc = grub_util_exec (systemctl);
 
+  /* `systemctl kexec` is "asynchronous" and will return even on success. */
+  if (rc == 0)
+    grub_sleep (10);
+
   if (kexecute == 1)
     grub_fatal (N_("error trying to perform 'systemctl kexec': %d"), rc);
 
Signature · 1 line
2.39.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Robbie Harwood

Per systemctl(1), it "is asynchronous; it will return after the reboot operation is enqueued, without waiting for it to complete". This differs from kexec(8), which calls reboot(2) and therefore does not return.

When not using fallback, this confusingly results in:

error trying to perform 'systemctl kexec': 0
Aborted. Press any key to exit.

Quoted 7 lines

on screen for a bit, followed by successful kexec.

To reduce the liklihood of hitting this case, add a delay on succesful return. Ultimately, the systemd interface is racy: we can't avoid it entirely unless we never fallback on success.

Daniel