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 <jiaqing.zhao@linux.intel.com>
Reviewed-by: Jian Jun Chen <jian.jun.chen@intel.com>
This commit is contained in:
Jiaqing Zhao 2024-08-29 07:55:04 +00:00 committed by acrnsi-robot
parent dbc3ff39aa
commit 8aca9eb12f
1 changed files with 15 additions and 0 deletions

View File

@ -29,6 +29,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>
@ -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);