mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH master 1/3] console: move full ctrl+c implementation into separate file
@ 2025-09-01 14:12 Ahmad Fatoum
  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
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2025-09-01 14:12 UTC (permalink / raw)
  To: barebox; +Cc: fpg, Ahmad Fatoum

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




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-09-01 17:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-01 14:12 [PATCH master 1/3] console: move full ctrl+c implementation into separate file Ahmad Fatoum
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox