From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1Vl5rk-0007no-EZ for mharc-grub-devel@gnu.org; Mon, 25 Nov 2013 18:46:56 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37052) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vl5rh-0007ne-HF for grub-devel@gnu.org; Mon, 25 Nov 2013 18:46:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vl5rg-0005MT-0y for grub-devel@gnu.org; Mon, 25 Nov 2013 18:46:53 -0500 Received: from mail-yh0-x249.google.com ([2607:f8b0:4002:c01::249]:43015) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vl5rf-0005MN-T7 for grub-devel@gnu.org; Mon, 25 Nov 2013 18:46:51 -0500 Received: by mail-yh0-f73.google.com with SMTP id f64so497310yha.0 for ; Mon, 25 Nov 2013 15:46:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=wMMgHJVcTxBIgntLVCs1Zc9werO51KO1mR3xYdmglRU=; b=UXqhNqg1dzupmHBnHbmNQlwacP2ubtzrSi9i/cfgeB4cKg5lHMHA0m+zwXIag0QFCM FPA+yiDSikLl500VPPyeQ19SAGXqSGIbyy1PMNm1ES56pQtMNkNf/ODPzQchXuKoo6eq 6bWjv4VK6LgsD4hLXbNnyi02QlmPFF4w6CW2/b2PPc8AFkgSf3kWDLcxX2uqU+YGuS5t 6wXTdYSl62GqsNFsb5P5cThwg9yX26B0Pzxc8o3Kzudt1r8Cfaqx1Tpr6QUxOBNoWsgh nBgtOTWqmMIjd5yMj9J9Pvwh1ozOZpyT4Vt2UTrYbE39WGRd+sj/6C5D8ZpxEeq/X+Lw xpVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=wMMgHJVcTxBIgntLVCs1Zc9werO51KO1mR3xYdmglRU=; b=K6BYbPTN/H7C/ibbjupv2RIdXCTzW9kr9UxY0B1jj55zD+2qXeJPLFIsbkFmL4AJGb c824K4vfWMPJW3l/2xl7pbsaBUZIznGxVgt1FLzoEK+hyXuDj/i1pjQtTHkrd0noU+JA BuKmr3IepUmk51+vSCeJ51v8JZgaFEoZmgGO1JumIsUKD//EnUs3qq9mnhiM5t+voUwP 2xwYgx4W1a1DcFj39GlCuo7gIfodBx6pcQkUoA313rjoGcFZPeMPKNvqUTFHxubfhwMZ 84dEatelG+LUT4ZxFOBWN1qLwGWdzUTzkQKQfZ30Ig5SZNkuHjS4z7Ge47zegEeHLlAT haxQ== X-Gm-Message-State: ALoCoQntaiQ39QzJGJmc/k+lpuRKpA8xf6r1MUSdrckxNvVUf64IQUcSxhC6BfwkeMCx+MWIH567Peg3Hn88JmC2JxA94PKIZkG2Nc1GaCtW1dlhgMGDwumUQan+1jM89wZ94CYA4QgGTQVk/a+UNJa7lu2+1yhx4W8iXWcDRkJvFGkka66LYz72APWD4fNIHcy/0sBE4c4T9UMK8DQWl4LAVkfGNa01963+MkAukC1RMYfSzrs0oDQ= X-Received: by 10.236.115.198 with SMTP id e46mr14501177yhh.33.1385423211055; Mon, 25 Nov 2013 15:46:51 -0800 (PST) Received: from corp2gmr1-2.hot.corp.google.com (corp2gmr1-2.hot.corp.google.com [172.24.189.93]) by gmr-mx.google.com with ESMTPS id v64si4935598yhm.3.2013.11.25.15.46.51 for (version=TLSv1.1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 25 Nov 2013 15:46:51 -0800 (PST) Received: from yinz.mtv.corp.google.com (yinz.mtv.corp.google.com [172.17.81.122]) by corp2gmr1-2.hot.corp.google.com (Postfix) with ESMTP id DEAD95A420E; Mon, 25 Nov 2013 15:46:50 -0800 (PST) Received: by yinz.mtv.corp.google.com (Postfix, from userid 184367) id 8700BC205C; Mon, 25 Nov 2013 15:46:50 -0800 (PST) From: Jon McCune To: grub-devel@gnu.org Subject: [PATCH v0] Require human interaction to go to normal shell if grub.cfg has a problem Date: Mon, 25 Nov 2013 15:46:48 -0800 Message-Id: <1385423208-18212-1-git-send-email-jonmccune@google.com> X-Mailer: git-send-email 1.8.4.1 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4002:c01::249 Cc: Jon McCune X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Nov 2013 23:46:55 -0000 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 --- 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 #include #include +#include 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