qemu-sanity-check/0001-init-Try-to-call-reboo...

63 lines
1.7 KiB
Diff

From 1a2ef4ef4740caeb0357c433004256ce33444a69 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Thu, 22 Aug 2013 15:40:57 +0100
Subject: [PATCH 1/4] init: Try to call reboot(2) to reboot the system from the
initramfs.
For some reason, panic=1 is broken on kernel 3.11. Calling reboot is
more reliable.
Note that qemu won't actually reboot the VM, because we are passing
-no-reboot on the command line, so the VM should exit instead.
---
configure.ac | 2 ++
init.c | 12 ++++++++++++
2 files changed, 14 insertions(+)
diff --git a/configure.ac b/configure.ac
index 791360f..1b3c22b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -28,6 +28,8 @@ test "x$U" != "x" && AC_MSG_ERROR([Compiler not ANSI compliant])
AM_PROG_CC_C_O
+AC_CHECK_HEADERS([sys/reboot.h])
+
dnl Allow the package to override the default list of qemu binary
dnl names which are tried, since this heavily depends on how qemu
dnl has been packaged in the downstream distro.
diff --git a/init.c b/init.c
index f19772b..ef7011c 100644
--- a/init.c
+++ b/init.c
@@ -22,6 +22,10 @@
#include <stdlib.h>
#include <unistd.h>
+#ifdef HAVE_SYS_REBOOT_H
+#include <sys/reboot.h>
+#endif
+
int
main (int argc, char *argv[])
{
@@ -29,6 +33,14 @@ main (int argc, char *argv[])
fprintf (stderr, "***** initrd started up OK *****\n");
fprintf (stderr, "\n");
fprintf (stderr, "\n");
+
+#if defined(HAVE_SYS_REBOOT_H) && defined(RB_AUTOBOOT)
+ /* Try to reboot the system. */
+ reboot (RB_AUTOBOOT);
+ perror ("reboot");
+ /* Reboot attempt failed, fallthrough below. */
+#endif
+
fprintf (stderr, "expect to see a kernel panic below, that is normal\n");
fprintf (stderr, "\n");
fprintf (stderr, "\n");
--
1.8.3.1