grub-devel.gnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v0] Require human interaction to go to normal shell if grub.cfg has a problem
@ 2013-11-25 23:46 Jon McCune
  2013-11-28  6:41 ` Vladimir 'phcoder' Serbinenko
  2013-11-28 17:34 ` Andrey Borzenkov
  0 siblings, 2 replies; 9+ messages in thread
From: Jon McCune @ 2013-11-25 23:46 UTC (permalink / raw)
  To: grub-devel; +Cc: Jon McCune

The rescue prompt is very useful for human operators, but not so
useful in unattended environments.  Add a facility for rebooting
after a delay, so that, e.g., the system can still PXE boot if
there is no console attached.

Signed-off-by: Jon McCune <jonmccune@google.com>
---
 grub-core/normal/main.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
index ad36273..f8953d5 100644
--- a/grub-core/normal/main.c
+++ b/grub-core/normal/main.c
@@ -32,6 +32,7 @@
 #include <grub/i18n.h>
 #include <grub/charset.h>
 #include <grub/script_sh.h>
+#include <grub/time.h>
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
@@ -333,6 +334,21 @@ grub_normal_execute (const char *config, int nested, int batch)
     }
 }
 
+/* Copied from grub-core/commands/sleep.c. */
+static int
+grub_interruptible_millisleep (grub_uint32_t ms)
+{
+  grub_uint64_t start;
+
+  start = grub_get_time_ms ();
+
+  while (grub_get_time_ms () - start < ms)
+    if (grub_getkey_noblock () == GRUB_TERM_ESC)
+      return 1;
+
+  return 0;
+}
+
 /* This starts the normal mode.  */
 void
 grub_enter_normal_mode (const char *config)
@@ -340,6 +356,15 @@ grub_enter_normal_mode (const char *config)
   grub_boot_time ("Entering normal mode");
   nested_level++;
   grub_normal_execute (config, 0, 0);
+  /* Control only returns from grub_normal_execute() if there is some kind of
+   * problem with grub.cfg, like it does not exist.  Reboot by default unless
+   * ESC is pressed within 5 seconds. */
+  grub_printf ("Press ESC in 5 seconds for a rescue shell.\n");
+  if (!grub_interruptible_millisleep (5000))
+    {
+      grub_printf ("Rebooting instead of going to rescue shell.\n");
+      grub_reboot ();
+    }
   grub_boot_time ("Entering shell");
   grub_cmdline_run (0);
   nested_level--;
-- 
1.8.4.1



^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-12-09 23:34 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-25 23:46 [PATCH v0] Require human interaction to go to normal shell if grub.cfg has a problem Jon McCune
2013-11-28  6:41 ` Vladimir 'phcoder' Serbinenko
2013-11-28 17:34 ` Andrey Borzenkov
2013-12-02 20:16   ` Jonathan McCune
2013-12-02 20:38     ` Andrey Borzenkov
2013-12-02 20:49       ` Jonathan McCune
2013-12-07 12:35         ` Andrey Borzenkov
2013-12-09 15:25           ` Jonathan McCune
2013-12-09 23:33             ` Vladimir 'φ-coder/phcoder' Serbinenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).