From 7d8af896c7c660a8608abe5efa82b52e9d9f097c Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Mon, 14 Sep 2020 15:37:46 +0200 Subject: sandbox: implement simple, ^C-interruptible, restart handler Typing reset in sandbox results in hang() while the terminal is not cooked and ^C is ineffective. Only way to terminate barebox then is via kill. Reinstate cooked mode on reset, so ^C termination is possible. Signed-off-by: Ahmad Fatoum Signed-off-by: Sascha Hauer --- arch/sandbox/board/poweroff.c | 12 ++++++++++++ arch/sandbox/mach-sandbox/include/mach/linux.h | 1 + arch/sandbox/os/common.c | 6 ++++++ 3 files changed, 19 insertions(+) (limited to 'arch') diff --git a/arch/sandbox/board/poweroff.c b/arch/sandbox/board/poweroff.c index 6b5a6dff15..5072b756e1 100644 --- a/arch/sandbox/board/poweroff.c +++ b/arch/sandbox/board/poweroff.c @@ -1,6 +1,7 @@ #include #include #include +#include #include static void sandbox_poweroff(struct poweroff_handler *poweroff) @@ -8,9 +9,20 @@ static void sandbox_poweroff(struct poweroff_handler *poweroff) linux_exit(); } +static void sandbox_rst_hang(struct restart_handler *rst) +{ + linux_hang(); +} + +static struct restart_handler rst_hang = { + .name = "hang", + .restart = sandbox_rst_hang +}; + static int poweroff_register_feature(void) { poweroff_handler_register_fn(sandbox_poweroff); + restart_handler_register(&rst_hang); return 0; } diff --git a/arch/sandbox/mach-sandbox/include/mach/linux.h b/arch/sandbox/mach-sandbox/include/mach/linux.h index 9759a376ec..f0a3a7b510 100644 --- a/arch/sandbox/mach-sandbox/include/mach/linux.h +++ b/arch/sandbox/mach-sandbox/include/mach/linux.h @@ -17,6 +17,7 @@ ssize_t linux_write(int fd, const void *buf, size_t count); off_t linux_lseek(int fildes, off_t offset); int linux_tstc(int fd); void __attribute__((noreturn)) linux_exit(void); +void linux_hang(void); int linux_execve(const char * filename, char *const argv[], char *const envp[]); diff --git a/arch/sandbox/os/common.c b/arch/sandbox/os/common.c index 437fe3ecdf..bbab3bd231 100644 --- a/arch/sandbox/os/common.c +++ b/arch/sandbox/os/common.c @@ -122,6 +122,12 @@ void __attribute__((noreturn)) linux_exit(void) exit(0); } +void linux_hang(void) +{ + cookmode(); + /* falls through to generic hang() */ +} + int linux_open(const char *filename, int readwrite) { return open(filename, readwrite ? O_RDWR : O_RDONLY); -- cgit v1.2.3