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 <[email protected]>
---
 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


Reply via email to