summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2019-02-25 12:37:39 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2019-04-24 10:11:18 +0200
commitec5f3d3dbbc054cf704a658d2734b67df466926b (patch)
treeeab1bd11acbd486b08e69951810fe6fbdb7f8f39 /common
parentc5f991d2ad8ea2d872fad64dee2fd660bb0a1b20 (diff)
downloadbarebox-ec5f3d3dbbc054cf704a658d2734b67df466926b.tar.gz
barebox-ec5f3d3dbbc054cf704a658d2734b67df466926b.tar.xz
console: forbid ctrlc during startup
When global.autoboot_abort_key is set to ctrl-c then the user is expected to press ctrl-c to get to the prompt. The user might press ctrl-c before the init script runs the "timeout" command. In this case the init script is aborted at arbitrary places which leads to inconsistent results depending on the place it is aborted. This patch introduces the global.console.ctrlc_allowed variable. When this variable is set to false ctrl-c is ignored entirely. The variable is set to false by default and changed to true in the init script. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r--common/console.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/common/console.c b/common/console.c
index b6685ecf6a..406722a1da 100644
--- a/common/console.c
+++ b/common/console.c
@@ -575,6 +575,7 @@ void console_flush(void)
EXPORT_SYMBOL(console_flush);
static int ctrlc_abort;
+static int ctrlc_allowed;
void ctrlc_handled(void)
{
@@ -586,6 +587,9 @@ int ctrlc(void)
{
int ret = 0;
+ if (!ctrlc_allowed)
+ return 0;
+
if (ctrlc_abort)
return 1;
@@ -605,5 +609,25 @@ int ctrlc(void)
}
EXPORT_SYMBOL(ctrlc);
+static int console_ctrlc_init(void)
+{
+ globalvar_add_simple_bool("console.ctrlc_allowed", &ctrlc_allowed);
+ return 0;
+}
+device_initcall(console_ctrlc_init);
+
+void console_ctrlc_allow(void)
+{
+ ctrlc_allowed = 1;
+}
+
+void console_ctrlc_forbid(void)
+{
+ ctrlc_allowed = 0;
+}
+
+BAREBOX_MAGICVAR_NAMED(global_console_ctrlc_allowed, global.console.ctrlc_allowed,
+ "If true, scripts can be aborted with ctrl-c");
+
BAREBOX_MAGICVAR_NAMED(global_linux_bootargs_console, global.linux.bootargs.console,
"console= argument for Linux from the stdout-path property in /chosen node");