From 8aca9eb12fdc81adce98af7c1183f7ea8cb019a6 Mon Sep 17 00:00:00 2001 From: Jiaqing Zhao Date: Thu, 29 Aug 2024 07:55:04 +0000 Subject: [PATCH] dm: uart: add escape sequence Ctrl-a x to exit dm When guest console is redirected to stdio, Ctrl-c is also passed to guest. Add escape sequence Ctrl-a x to send SIGINT to exit acrn-dm in such case. Tracked-On: #8731 Signed-off-by: Jiaqing Zhao Reviewed-by: Jian Jun Chen --- devicemodel/hw/uart_core.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/devicemodel/hw/uart_core.c b/devicemodel/hw/uart_core.c index d001b9800..5ec35c3ed 100644 --- a/devicemodel/hw/uart_core.c +++ b/devicemodel/hw/uart_core.c @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -94,6 +95,8 @@ static struct { { COM5_BASE, COM5_IRQ, false}, }; +static bool stdio_ctrl_a_pressed = false; + #define UART_NLDEVS (ARRAY_SIZE(uart_lres)) enum uart_be_type { @@ -717,6 +720,18 @@ uart_backend_read(struct uart_backend *be) switch (be->be_type) { case UART_BE_STDIO: + rc = read(be->fd, &rb, 1); + if (rb == 0x01) { // Ctrl-a + DPRINTF(("%s: Got Ctrl-a\n", __func__)); + stdio_ctrl_a_pressed = true; + } else if (stdio_ctrl_a_pressed) { + if (rb == 'x') { + DPRINTF(("%s: Got Ctrl-a x\n", __func__)); + kill(getpid(), SIGINT); + } + stdio_ctrl_a_pressed = false; + } + break; case UART_BE_TTY: /* fd is used to read */ rc = read(be->fd, &rb, 1);