From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 4/5] console: give each console implementation its own console_ctrlc()
Date: Sun, 8 Nov 2026 10:32:06 +0100 [thread overview]
Message-ID: <20261108093354.1247607-5-a.fatoum@barebox.org> (raw)
In-Reply-To: <20261108093354.1247607-1-a.fatoum@barebox.org>
ctrlc_non_interruptible() reads the console input itself, inside an
ifdef for the architectures that bring their own check. Have the full
and the simple console each provide a console_ctrlc() for it instead,
so that they can check differently, and test CONFIG_ARCH_HAS_CTRLC with
IS_ENABLED().
No functional change.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
common/console.c | 10 ++++++++++
common/console_ctrlc.c | 10 ++++------
common/console_simple.c | 10 ++++++++++
include/console.h | 4 ++--
4 files changed, 26 insertions(+), 8 deletions(-)
diff --git a/common/console.c b/common/console.c
index 0722af0a40fc..c57bb87b0114 100644
--- a/common/console.c
+++ b/common/console.c
@@ -605,6 +605,16 @@ int pollchar(ktime_t duration)
}
EXPORT_SYMBOL(pollchar);
+/**
+ * console_ctrlc - check the console input for a Ctrl-C
+ *
+ * Return: true if Ctrl-C was pressed
+ */
+bool console_ctrlc(void)
+{
+ return tstc() && getchar() == 3;
+}
+
int console_putc(struct console_device *con, char c)
{
bool crlf = c == '\n';
diff --git a/common/console_ctrlc.c b/common/console_ctrlc.c
index 6fbe07252eff..5c912841c694 100644
--- a/common/console_ctrlc.c
+++ b/common/console_ctrlc.c
@@ -28,12 +28,10 @@ int ctrlc_non_interruptible(void)
if (ctrlc_abort)
return 1;
-#ifdef CONFIG_ARCH_HAS_CTRLC
- ret = arch_ctrlc();
-#else
- if (tstc() && getchar() == 3)
- ret = 1;
-#endif
+ if (IS_ENABLED(CONFIG_ARCH_HAS_CTRLC))
+ ret = arch_ctrlc();
+ else
+ ret = console_ctrlc();
if (ret)
ctrlc_abort = 1;
diff --git a/common/console_simple.c b/common/console_simple.c
index 6771d457455e..97beec2d8d2e 100644
--- a/common/console_simple.c
+++ b/common/console_simple.c
@@ -80,6 +80,16 @@ int pollchar(ktime_t duration)
}
EXPORT_SYMBOL(pollchar);
+/**
+ * console_ctrlc - check the console input for a Ctrl-C
+ *
+ * Return: true if Ctrl-C was pressed
+ */
+bool console_ctrlc(void)
+{
+ return tstc() && getchar() == 3;
+}
+
void console_flush(void)
{
if (console && console->flush)
diff --git a/include/console.h b/include/console.h
index 4b2893d5c4df..6469802531d5 100644
--- a/include/console.h
+++ b/include/console.h
@@ -239,9 +239,7 @@ static inline int barebox_set_loglevel(int loglevel)
}
#endif
-#ifdef CONFIG_ARCH_HAS_CTRLC
int arch_ctrlc(void);
-#endif
#ifndef CONFIG_CONSOLE_NONE
/* stdout */
@@ -255,6 +253,7 @@ int console_vprintf(struct console_device *con, const char *fmt, va_list args);
int ctrlc(void);
int ctrlc_non_interruptible(void);
+bool console_ctrlc(void);
void ctrlc_handled(void);
void console_ctrlc_allow(void);
void console_ctrlc_forbid(void);
@@ -266,6 +265,7 @@ static inline void console_flush(void) {}
/* test if ctrl-c was pressed */
static inline int ctrlc (void) { return 0; }
static inline int ctrlc_non_interruptible(void) { return 0; }
+static inline bool console_ctrlc(void) { return false; }
static inline void ctrlc_handled(void) { }
static inline void console_ctrlc_allow(void) { }
static inline void console_ctrlc_forbid(void) { }
--
2.47.3
next prev parent reply other threads:[~2026-11-08 9:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-08 9:32 [PATCH 0/5] console: escape sequence handling improvement Ahmad Fatoum
2026-11-08 9:32 ` [PATCH 1/5] readkey: wait for the rest of an escape sequence Ahmad Fatoum
2026-11-08 9:32 ` [PATCH 2/5] lib: term: ask the terminal when a console can't tell its size Ahmad Fatoum
2026-11-08 9:32 ` [PATCH 3/5] serial: virtio_console: report the console size Ahmad Fatoum
2026-11-08 9:32 ` Ahmad Fatoum [this message]
2026-11-08 9:32 ` [PATCH 5/5] console: keep the keys typed ahead when checking for Ctrl-C Ahmad Fatoum
2026-11-09 9:50 ` [PATCH 0/5] console: escape sequence handling improvement 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=20261108093354.1247607-5-a.fatoum@barebox.org \
--to=a.fatoum@barebox.org \
--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