diff options
author | Samuel Mendoza-Jonas <sam@mendozajonas.com> | 2017-10-31 10:49:51 +1100 |
---|---|---|
committer | Samuel Mendoza-Jonas <sam@mendozajonas.com> | 2017-11-14 16:33:41 +1100 |
commit | 8d1e4f053574d69aae89af19983c96500b4156a4 (patch) | |
tree | 190c566638fac6bbcc7964566cbe75e6d05d3fff /ui/ncurses/nc-cui.c | |
parent | 669083ee9eda63af65d7cfc43968947f09162996 (diff) | |
download | talos-petitboot-8d1e4f053574d69aae89af19983c96500b4156a4.tar.gz talos-petitboot-8d1e4f053574d69aae89af19983c96500b4156a4.zip |
ui/ncurses: Safely handle lost terminal control commandsv1.6.3
Normally terminal control commands are caught and handled before ncurses
or Petitboot could see them. However several combinations of broken
terminal emulators or console connections can cause these command
sequences to be seen by Petitboot, usually resulting in Petitboot
exiting due to the ESC character and then the rest printed to the
console.
Aside from confusing the user this can also cancel autoboot, so it's
important we don't let these sequences go unnoticed if possible.
In ui/ncurses/console-codes we add a state machine that recognises the
syntax of these control/escape sequences and handles the lost
characters. We don't try to emulate the functionality of these commands,
instead just logging them for reference.
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Diffstat (limited to 'ui/ncurses/nc-cui.c')
-rw-r--r-- | ui/ncurses/nc-cui.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/ui/ncurses/nc-cui.c b/ui/ncurses/nc-cui.c index 6ced24c..8060510 100644 --- a/ui/ncurses/nc-cui.c +++ b/ui/ncurses/nc-cui.c @@ -21,6 +21,7 @@ #endif #include <assert.h> +#include <ctype.h> #include <errno.h> #include <stdlib.h> #include <string.h> @@ -45,6 +46,7 @@ #include "nc-statuslog.h" #include "nc-subset.h" #include "nc-plugin.h" +#include "console-codes.h" extern const struct help_text main_menu_help_text; extern const struct help_text plugin_menu_help_text; @@ -524,6 +526,9 @@ static bool process_global_keys(struct cui *cui, int key) static int cui_process_key(void *arg) { struct cui *cui = cui_from_arg(arg); + unsigned int i; + char *sequence; + int grab; assert(cui->current); @@ -535,6 +540,29 @@ static int cui_process_key(void *arg) if (c == ERR) break; + if (c == 27) { + /* + * If this is a console code sequence try to parse it + * and don't treat this as a key press. + */ + grab = getch(); + if (grab != ERR && grab != 27) { + ungetch(grab); + pb_debug("%s: Caught unhandled command sequence\n", + __func__); + sequence = handle_control_sequence(cui, c); + pb_debug("Caught sequence "); + if (sequence) { + pb_debug("(%zu): ", strlen(sequence)); + for (i = 0; i < strlen(sequence); i++) + pb_debug("0%o ", sequence[i]); + pb_debug("\n"); + } else + pb_debug("(0): (none)\n"); + continue; + } + } + if (!cui->has_input) { cui->has_input = true; if (cui->client) { |