6a9365c
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
6a9365c
From: Robbie Harwood <rharwood@redhat.com>
6a9365c
Date: Wed, 22 Mar 2023 14:19:43 -0400
6a9365c
Subject: [PATCH] emu/linux: work around systemctl kexec returning
6a9365c
6a9365c
Per systemctl(1), it "is asynchronous; it will return after the reboot
6a9365c
operation is enqueued, without waiting for it to complete".  This
6a9365c
differs from kexec(8), which calls reboot(2) and therefore does not
6a9365c
return.
6a9365c
6a9365c
When not using fallback, this results in the confusing-but-harmless:
6a9365c
6a9365c
    error trying to perform 'systemctl kexec': 0
6a9365c
    Aborted. Press any key to exit.
6a9365c
6a9365c
on screen for a bit, followed by successful kexec.
6a9365c
6a9365c
To reduce the liklihood of hitting this case, add a delay on succesful
6a9365c
return.  Ultimately, the systemd interface is racy: we can't avoid it
6a9365c
entirely unless we never fallback on success.
6a9365c
6a9365c
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
6a9365c
---
6a9365c
 grub-core/loader/emu/linux.c | 4 ++++
6a9365c
 1 file changed, 4 insertions(+)
6a9365c
6a9365c
diff --git a/grub-core/loader/emu/linux.c b/grub-core/loader/emu/linux.c
6a9365c
index 0cf378a376..7de3f7f861 100644
6a9365c
--- a/grub-core/loader/emu/linux.c
6a9365c
+++ b/grub-core/loader/emu/linux.c
6a9365c
@@ -74,6 +74,10 @@ grub_linux_boot (void)
6a9365c
 		(kexecute==1) ? "do-or-die" : "just-in-case");
6a9365c
   rc = grub_util_exec (systemctl);
6a9365c
 
6a9365c
+  /* `systemctl kexec` is "asynchronous" and will return even on success. */
6a9365c
+  if (rc == 0)
6a9365c
+    grub_sleep (10);
6a9365c
+
6a9365c
   if (kexecute == 1)
6a9365c
     grub_fatal (N_("error trying to perform 'systemctl kexec': %d"), rc);
6a9365c