From: Robbie Harwood Date: Thu, 23 Mar 2023 15:59:51 +0000 (-0400) Subject: loader/emu/linux: Work around systemctl kexec returning X-Git-Tag: grub-2.12-rc1~99 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b8b072ddcddfa2f4389c17884f5686f741730456;p=thirdparty%2Fgrub.git loader/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 likelihood of hitting this case, add a delay on successful return. Ultimately, the systemd interface is racy: we can't avoid it entirely unless we never fallback on success. Signed-off-by: Robbie Harwood Reviewed-by: Daniel Kiper --- diff --git a/grub-core/loader/emu/linux.c b/grub-core/loader/emu/linux.c index 0cf378a37..7de3f7f86 100644 --- a/grub-core/loader/emu/linux.c +++ b/grub-core/loader/emu/linux.c @@ -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);