From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: fpg@pengutronix.de, Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master 1/3] console: move full ctrl+c implementation into separate file
Date: Mon, 1 Sep 2025 16:12:55 +0200 [thread overview]
Message-ID: <20250901141259.415561-1-a.fatoum@pengutronix.de> (raw)
There is no reason to keep different ctrl+c implementations for the full
and simple console case. In preparation for unifying them, move the
implementation into its own file.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/Makefile | 2 +-
common/console.c | 60 -------------------------------------
common/console_ctrlc.c | 67 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 68 insertions(+), 61 deletions(-)
create mode 100644 common/console_ctrlc.c
diff --git a/common/Makefile b/common/Makefile
index 7a91ef21f79b..9f98de72854f 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -32,7 +32,7 @@ obj-$(CONFIG_BOOTM) += bootm.o booti.o
obj-$(CONFIG_CMD_LOADS) += s_record.o
obj-$(CONFIG_MEMTEST) += memtest.o
obj-$(CONFIG_COMMAND_SUPPORT) += command.o
-obj-$(CONFIG_CONSOLE_FULL) += console.o
+obj-$(CONFIG_CONSOLE_FULL) += console.o console_ctrlc.o
obj-$(CONFIG_CONSOLE_SIMPLE) += console_simple.o
obj-y += console_countdown.o
obj-pbl-$(CONFIG_DDR_SPD) += ddr_spd.o
diff --git a/common/console.c b/common/console.c
index dc552e4c5dac..a31433a659e2 100644
--- a/common/console.c
+++ b/common/console.c
@@ -635,65 +635,5 @@ void console_flush(void)
}
EXPORT_SYMBOL(console_flush);
-static int ctrlc_abort;
-static int ctrlc_allowed;
-
-void ctrlc_handled(void)
-{
- ctrlc_abort = 0;
-}
-
-int ctrlc_non_interruptible(void)
-{
- int ret = 0;
-
- if (!ctrlc_allowed)
- return 0;
-
- if (ctrlc_abort)
- return 1;
-
-#ifdef CONFIG_ARCH_HAS_CTRLC
- ret = arch_ctrlc();
-#else
- if (tstc() && getchar() == 3)
- ret = 1;
-#endif
-
- if (ret)
- ctrlc_abort = 1;
-
- return ret;
-}
-EXPORT_SYMBOL(ctrlc_non_interruptible);
-
-/* test if ctrl-c was pressed */
-int ctrlc(void)
-{
- resched();
- return ctrlc_non_interruptible();
-}
-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(global.console.ctrlc_allowed,
- "If true, scripts can be aborted with ctrl-c");
-
BAREBOX_MAGICVAR(global.linux.bootargs.console,
"console= argument for Linux from the stdout-path property in /chosen node");
diff --git a/common/console_ctrlc.c b/common/console_ctrlc.c
new file mode 100644
index 000000000000..0272eec280d1
--- /dev/null
+++ b/common/console_ctrlc.c
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <stdio.h>
+#include <console.h>
+#include <sched.h>
+#include <globalvar.h>
+#include <magicvar.h>
+
+static int ctrlc_abort;
+static int ctrlc_allowed;
+
+void ctrlc_handled(void)
+{
+ ctrlc_abort = 0;
+}
+
+int ctrlc_non_interruptible(void)
+{
+ int ret = 0;
+
+ if (!ctrlc_allowed)
+ return 0;
+
+ if (ctrlc_abort)
+ return 1;
+
+#ifdef CONFIG_ARCH_HAS_CTRLC
+ ret = arch_ctrlc();
+#else
+ if (tstc() && getchar() == 3)
+ ret = 1;
+#endif
+
+ if (ret)
+ ctrlc_abort = 1;
+
+ return ret;
+}
+EXPORT_SYMBOL(ctrlc_non_interruptible);
+
+/* test if ctrl-c was pressed */
+int ctrlc(void)
+{
+ resched();
+ return ctrlc_non_interruptible();
+}
+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(global.console.ctrlc_allowed,
+ "If true, scripts can be aborted with ctrl-c");
--
2.47.2
next reply other threads:[~2025-09-01 17:29 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-01 14:12 Ahmad Fatoum [this message]
2025-09-01 14:12 ` [PATCH master 2/3] console: simple: use common ctrl+c implementation Ahmad Fatoum
2025-09-01 14:12 ` [PATCH master 3/3] sandbox: add simpleconsole_defconfig Ahmad Fatoum
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=20250901141259.415561-1-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=fpg@pengutronix.de \
/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