From: Nigel Cunningham <nigel@suspend2.net>
To: linux-kernel@vger.kernel.org
Subject: [Suspend2][ 17/21] [Suspend2] Early boot message support.
Date: Tue, 27 Jun 2006 14:42:10 +1000 [thread overview]
Message-ID: <20060627044209.14883.17428.stgit@nigel.suspend2.net> (raw)
In-Reply-To: <20060627044112.14883.55823.stgit@nigel.suspend2.net>
Give the user the option of continuing or rebooting when we discover a
problem really early in the resume, prior to userspace program being
started. We may not even be able to start the userspace program, so we need
limited support for user interaction - that or we need to always invalidate
images if problems occur or such like.
Some would complain that the kernel shouldn't be seeking to interact with
the user. While I see that argument, it seems to me that helping the user
do what they want to do is far more important. The prompt has a timeout, so
we won't hang indefinitely if there's no response.
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/ui.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 108 insertions(+), 0 deletions(-)
diff --git a/kernel/power/ui.c b/kernel/power/ui.c
index 2012c2a..3d246e4 100644
--- a/kernel/power/ui.c
+++ b/kernel/power/ui.c
@@ -563,3 +563,111 @@ void suspend_cleanup_console(void)
}
#endif
+/* suspend_early_boot_message()
+ * Description: Handle errors early in the process of booting.
+ * The user may press C to continue booting, perhaps
+ * invalidating the image, or space to reboot.
+ * This works from either the serial console or normally
+ * attached keyboard.
+ *
+ * Note that we come in here from init, while the kernel is
+ * locked. If we want to get events from the serial console,
+ * we need to temporarily unlock the kernel.
+ *
+ * suspend_early_boot_message may also be called post-boot.
+ * In this case, it simply printks the message and returns.
+ *
+ * Arguments: int Whether we are able to erase the image.
+ * int default_answer. What to do when we timeout. This
+ * will normally be continue, but the user might
+ * provide command line options (__setup) to override
+ * particular cases.
+ * Char *. Pointer to a string explaining why we're moaning.
+ */
+
+#define say(message, a...) printk(KERN_EMERG message, ##a)
+#define message_timeout 25 /* message_timeout * 10 must fit in 8 bits */
+
+int suspend_early_boot_message(int message_detail, int default_answer, char *warning_reason, ...)
+{
+ unsigned long orig_state = get_suspend_state(), continue_req = 0;
+ va_list args;
+ int printed_len;
+
+ if (warning_reason) {
+ va_start(args, warning_reason);
+ printed_len = vsnprintf(local_printf_buf,
+ sizeof(local_printf_buf),
+ warning_reason,
+ args);
+ va_end(args);
+ }
+
+ if (!test_suspend_state(SUSPEND_BOOT_TIME)) {
+ printk(name_suspend "%s\n", local_printf_buf);
+ return default_answer;
+ }
+
+ /* We might be called directly from do_mounts_initrd if the
+ * user fails to set up their initrd properly. We need to
+ * enable the keyboard handler by setting the running flag */
+ set_suspend_state(SUSPEND_RUNNING);
+
+#if defined(CONFIG_VT) || defined(CONFIG_SERIAL_CONSOLE)
+ console_loglevel = 7;
+
+ say("=== Suspend2 ===\n\n");
+ if (warning_reason) {
+ say("BIG FAT WARNING!! %s\n\n", local_printf_buf);
+ switch (message_detail) {
+ case 0:
+ say("If you continue booting, note that any image WILL NOT BE REMOVED.\n");
+ say("Suspend is unable to do so because the appropriate modules aren't\n");
+ say("loaded. You should manually remove the image to avoid any\n");
+ say("possibility of corrupting your filesystem(s) later.\n");
+ break;
+ case 1:
+ say("If you want to use the current suspend image, reboot and try\n");
+ say("again with the same kernel that you suspended from. If you want\n");
+ say("to forget that image, continue and the image will be erased.\n");
+ break;
+ }
+ say("Press SPACE to reboot or C to continue booting with this kernel\n\n");
+ say("Default action if you don't select one in %d seconds is: %s.\n",
+ message_timeout,
+ default_answer == SUSPEND_CONTINUE_REQ ?
+ "continue booting" : "reboot");
+ } else {
+ say("BIG FAT WARNING!!\n\n");
+ say("You have tried to resume from this image before.\n");
+ say("If it failed once, it may well fail again.\n");
+ say("Would you like to remove the image and boot normally?\n");
+ say("This will be equivalent to entering noresume2 on the\n");
+ say("kernel command line.\n\n");
+ say("Press SPACE to remove the image or C to continue resuming.\n\n");
+ say("Default action if you don't select one in %d seconds is: %s.\n",
+ message_timeout,
+ !!default_answer ?
+ "continue resuming" : "remove the image");
+ }
+
+ set_suspend_state(SUSPEND_SANITY_CHECK_PROMPT);
+ clear_suspend_state(SUSPEND_CONTINUE_REQ);
+
+ if (suspend_wait_for_keypress(message_timeout) == 0) /* We timed out */
+ continue_req = !!default_answer;
+ else
+ continue_req = test_suspend_state(SUSPEND_CONTINUE_REQ);
+
+ if ((warning_reason) && (!continue_req))
+ machine_restart(NULL);
+
+ restore_suspend_state(orig_state);
+ if (continue_req)
+ set_suspend_state(SUSPEND_CONTINUE_REQ);
+
+#endif /* CONFIG_VT or CONFIG_SERIAL_CONSOLE */
+ return -EPERM;
+}
+#undef say
+
--
Nigel Cunningham nigel at suspend2 dot net
next prev parent reply other threads:[~2006-06-27 4:48 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-06-27 4:41 [Suspend2][ 00/21] User interface Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 01/21] [Suspend2] User interface c header Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 02/21] [Suspend2] Modify action state Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 03/21] [Suspend2] Tell userspace to redraw the screen Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 04/21] [Suspend2] Process abort request Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 05/21] [Suspend2] Receive a message from the userui Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 06/21] [Suspend2] Get userui storage needed Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 07/21] [Suspend2] Serialise userui configuration info Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 08/21] [Suspend2] Get amount of memory needed for userui Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 09/21] [Suspend2] Update progress bar Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 10/21] [Suspend2] __suspend_message Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 11/21] [Suspend2] Wait for keypress Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 12/21] [Suspend2] Abort a cycle Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 13/21] [Suspend2] Main message output Nigel Cunningham
2006-06-27 4:42 ` [Suspend2][ 14/21] [Suspend2] Conditionally pause Nigel Cunningham
2006-06-27 4:42 ` [Suspend2][ 15/21] [Suspend2] Prepare ui for work Nigel Cunningham
2006-06-27 4:42 ` [Suspend2][ 16/21] [Suspend2] Cleanup console after suspending Nigel Cunningham
2006-06-27 4:42 ` Nigel Cunningham [this message]
2006-06-27 4:42 ` [Suspend2][ 18/21] [Suspend2] Userspace proc entries Nigel Cunningham
2006-06-27 4:42 ` [Suspend2][ 19/21] [Suspend2] Operations for userspace interface module Nigel Cunningham
2006-06-27 4:42 ` [Suspend2][ 20/21] [Suspend2] Load time initialisation for user interface code Nigel Cunningham
2006-06-27 4:42 ` [Suspend2][ 21/21] [Suspend2] kernel/power/ui.h Nigel Cunningham
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060627044209.14883.17428.stgit@nigel.suspend2.net \
--to=nigel@suspend2.net \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome