Skip to content

Commit

Permalink
console_countdown: ignore errors in getchar()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Sascha Hauer <[email protected]>
  • Loading branch information
aleksander0m authored and saschahauer committed Sep 26, 2017
1 parent b2ac13f commit 0b8f344
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions common/console_countdown.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand Down

0 comments on commit 0b8f344

Please sign in to comment.