* [PATCH] console_countdown: ignore errors in getchar()
@ 2017-09-20 19:07 Aleksander Morgado
2017-09-26 6:48 ` Sascha Hauer
0 siblings, 1 reply; 2+ messages in thread
From: Aleksander Morgado @ 2017-09-20 19:07 UTC (permalink / raw)
To: barebox; +Cc: Aleksander Morgado
The getchar() call may return an error reported as a -1, e.g. when the
console detects a RATP message and switches to RATP mode.
In general it probably is a good idea to ignore these errors in the
console countdown operation; and in particular for the RATP usecase,
this also prevents from interfering with the countdown and menu just
when switching one of the consoles to RATP mode.
As a hint, this is what the standard console was printing due to this
issue when the RATP console was activated:
Hit m for menu or any other key to stop autoboot: [: missing `]'
Signed-off-by: Aleksander Morgado <aleksander@aleksander.es>
---
common/console_countdown.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/common/console_countdown.c b/common/console_countdown.c
index 03b9b3353..36da1ce57 100644
--- a/common/console_countdown.c
+++ b/common/console_countdown.c
@@ -47,12 +47,14 @@ int console_countdown(int timeout_s, unsigned flags, char *out_key)
do {
if (tstc()) {
key = getchar();
- if (flags & CONSOLE_COUNTDOWN_ANYKEY)
- goto out;
- if (flags & CONSOLE_COUNTDOWN_RETURN && key == '\n')
- goto out;
- if (flags & CONSOLE_COUNTDOWN_CTRLC && key == 3)
- goto out;
+ if (key >= 0) {
+ if (flags & CONSOLE_COUNTDOWN_ANYKEY)
+ goto out;
+ if (flags & CONSOLE_COUNTDOWN_RETURN && key == '\n')
+ goto out;
+ if (flags & CONSOLE_COUNTDOWN_CTRLC && key == 3)
+ goto out;
+ }
key = 0;
}
if ((flags & CONSOLE_COUNTDOWN_EXTERN) &&
--
2.14.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] console_countdown: ignore errors in getchar()
2017-09-20 19:07 [PATCH] console_countdown: ignore errors in getchar() Aleksander Morgado
@ 2017-09-26 6:48 ` Sascha Hauer
0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2017-09-26 6:48 UTC (permalink / raw)
To: Aleksander Morgado; +Cc: barebox
On Wed, Sep 20, 2017 at 12:07:16PM -0700, Aleksander Morgado wrote:
> The getchar() call may return an error reported as a -1, e.g. when the
> console detects a RATP message and switches to RATP mode.
>
> In general it probably is a good idea to ignore these errors in the
> console countdown operation; and in particular for the RATP usecase,
> this also prevents from interfering with the countdown and menu just
> when switching one of the consoles to RATP mode.
>
> As a hint, this is what the standard console was printing due to this
> issue when the RATP console was activated:
>
> Hit m for menu or any other key to stop autoboot: [: missing `]'
>
> Signed-off-by: Aleksander Morgado <aleksander@aleksander.es>
> ---
> common/console_countdown.c | 14 ++++++++------
> 1 file changed, 8 insertions(+), 6 deletions(-)
Applied, thanks
Sascha
>
> diff --git a/common/console_countdown.c b/common/console_countdown.c
> index 03b9b3353..36da1ce57 100644
> --- a/common/console_countdown.c
> +++ b/common/console_countdown.c
> @@ -47,12 +47,14 @@ int console_countdown(int timeout_s, unsigned flags, char *out_key)
> do {
> if (tstc()) {
> key = getchar();
> - if (flags & CONSOLE_COUNTDOWN_ANYKEY)
> - goto out;
> - if (flags & CONSOLE_COUNTDOWN_RETURN && key == '\n')
> - goto out;
> - if (flags & CONSOLE_COUNTDOWN_CTRLC && key == 3)
> - goto out;
> + if (key >= 0) {
> + if (flags & CONSOLE_COUNTDOWN_ANYKEY)
> + goto out;
> + if (flags & CONSOLE_COUNTDOWN_RETURN && key == '\n')
> + goto out;
> + if (flags & CONSOLE_COUNTDOWN_CTRLC && key == 3)
> + goto out;
> + }
> key = 0;
> }
> if ((flags & CONSOLE_COUNTDOWN_EXTERN) &&
> --
> 2.14.1
>
>
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-09-26 6:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-20 19:07 [PATCH] console_countdown: ignore errors in getchar() Aleksander Morgado
2017-09-26 6:48 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox