sandbox: Allow Ctrl-C to work in sandbox
It is useful for Cltl-C to be handled by U-Boot as it is on other boards.
But it is also useful to be able to terminate U-Boot with Ctrl-C.
Add an option to enable signals while in raw mode, and make this the
default. Add an option to leave the terminal cooked, which is useful for
redirecting output.
Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index 52e1096..9de71bb 100644
--- a/arch/sandbox/cpu/os.c
+++ b/arch/sandbox/cpu/os.c
@@ -104,21 +104,22 @@
/* Restore tty state when we exit */
static struct termios orig_term;
+static bool term_setup;
static void os_fd_restore(void)
{
- tcsetattr(0, TCSANOW, &orig_term);
+ if (term_setup)
+ tcsetattr(0, TCSANOW, &orig_term);
}
/* Put tty into raw mode so <tab> and <ctrl+c> work */
-void os_tty_raw(int fd)
+void os_tty_raw(int fd, bool allow_sigs)
{
- static int setup = 0;
struct termios term;
- if (setup)
+ if (term_setup)
return;
- setup = 1;
+ term_setup = true;
/* If not a tty, don't complain */
if (tcgetattr(fd, &orig_term))
@@ -128,7 +129,7 @@
term.c_iflag = IGNBRK | IGNPAR;
term.c_oflag = OPOST | ONLCR;
term.c_cflag = CS8 | CREAD | CLOCAL;
- term.c_lflag = 0;
+ term.c_lflag = allow_sigs ? ISIG : 0;
if (tcsetattr(fd, TCSANOW, &term))
return;