mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 2/4] console: forbid ctrlc during startup
Date: Wed, 24 Apr 2019 12:26:48 +0200	[thread overview]
Message-ID: <20190424102650.9257-2-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20190424102650.9257-1-s.hauer@pengutronix.de>

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>
---
 common/console.c                      | 24 ++++++++++++++++++++++++
 defaultenv/defaultenv-2-base/bin/init |  2 ++
 include/console.h                     |  3 +++
 3 files changed, 29 insertions(+)

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");
diff --git a/defaultenv/defaultenv-2-base/bin/init b/defaultenv/defaultenv-2-base/bin/init
index 8d02e3d3ab..a5d3a984f7 100644
--- a/defaultenv/defaultenv-2-base/bin/init
+++ b/defaultenv/defaultenv-2-base/bin/init
@@ -60,6 +60,8 @@ if [ "$autoboot" = 0 ]; then
 	autoboot="$?"
 fi
 
+global.console.ctrlc_allowed=true
+
 if [ "${key}" = "q" ]; then
 	exit
 fi
diff --git a/include/console.h b/include/console.h
index 673921331d..4062e5abf6 100644
--- a/include/console.h
+++ b/include/console.h
@@ -207,4 +207,7 @@ static inline void pbl_set_putc(void (*putcf)(void *ctx, int c), void *ctx) {}
 
 bool console_allow_color(void);
 
+void console_ctrlc_allow(void);
+void console_ctrlc_forbid(void);
+
 #endif
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2019-04-24 10:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-24 10:26 [PATCH 1/4] Shell: Handle aborting loops better Sascha Hauer
2019-04-24 10:26 ` Sascha Hauer [this message]
2019-04-24 10:26 ` [PATCH 3/4] console_countdown: Add pattern list Sascha Hauer
2019-04-24 10:26 ` [PATCH 4/4] defaultenv: Convert init script to C Sascha Hauer
2019-04-26 12:37   ` Roland Hieber
2019-04-29  6:57     ` Sascha Hauer

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=20190424102650.9257-2-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.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