Skip to content

Commit 58598a8

Browse files
committed
Enable ISIG control mode of termios after exit
The ISIG control mode is disabled in capture_keyboard_input(), but it is not reset in reset_keyboard_input(). This inconsistency causes default keyboard signal malfunctions (e.g., SIGINT from CTRL+C) after exit. To fix this, the termios control flag is encapsulated in a macro, TERMIOS_C_CFLAG and used in both capture_keyboard_input() and reset_keyboard_input().
1 parent 333254e commit 58598a8

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

uart.c

+19-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,23 @@
1010
#include "riscv.h"
1111
#include "riscv_private.h"
1212

13+
/*
14+
* The control mode flag for keyboard.
15+
*
16+
* ICANON: Enable canonical mode.
17+
* ECHO: Echo input characters.
18+
* ISIG: When any of the characters INTR, QUIT,
19+
* SUSP, or DSUSP are received, generate the
20+
* corresponding signal.
21+
*
22+
* It is essential to re-enable ISIG upon exit.
23+
* Otherwise, the default signal handler will
24+
* not catch the signal. E.g., SIGINT generated by
25+
* CTRL + c.
26+
*
27+
*/
28+
#define TERMIOS_C_CFLAG (ICANON | ECHO | ISIG)
29+
1330
/* Emulate 8250 (plain, without loopback mode support) */
1431

1532
#define U8250_INT_THRE 1
@@ -19,7 +36,7 @@ static void reset_keyboard_input()
1936
/* Re-enable echo, etc. on keyboard. */
2037
struct termios term;
2138
tcgetattr(0, &term);
22-
term.c_lflag |= ICANON | ECHO;
39+
term.c_lflag |= TERMIOS_C_CFLAG;
2340
tcsetattr(0, TCSANOW, &term);
2441
}
2542

@@ -31,7 +48,7 @@ void capture_keyboard_input()
3148

3249
struct termios term;
3350
tcgetattr(0, &term);
34-
term.c_lflag &= ~(ICANON | ECHO | ISIG); /* Disable echo as well */
51+
term.c_lflag &= ~TERMIOS_C_CFLAG; /* Disable echo as well */
3552
tcsetattr(0, TCSANOW, &term);
3653
}
3754

0 commit comments

Comments
 (0)