From 0bc9149a23a00c863ac3c6a3b8cf260f79dc9997 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 25 Jun 2024 16:09:19 +0800 Subject: [PATCH] IO: improve `ffGetTerminalResponse` --- src/common/io/io_unix.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/common/io/io_unix.c b/src/common/io/io_unix.c index 20eb3b3b0..3912582e6 100644 --- a/src/common/io/io_unix.c +++ b/src/common/io/io_unix.c @@ -142,28 +142,28 @@ const char* ffGetTerminalResponse(const char* request, const char* format, ...) if (!isatty(STDIN_FILENO)) { if (ftty < 0) - ftty = open("/dev/tty", O_RDWR | O_CLOEXEC); + ftty = open("/dev/tty", O_RDWR | O_NOCTTY | O_CLOEXEC); fin = ftty; } if (!isatty(STDOUT_FILENO)) { if (ftty < 0) - ftty = open("/dev/tty", O_RDWR | O_CLOEXEC); + ftty = open("/dev/tty", O_RDWR | O_NOCTTY | O_CLOEXEC); fout = ftty; } - struct termios oldTerm, newTerm; + struct termios oldTerm; if(tcgetattr(fin, &oldTerm) == -1) return "tcgetattr(STDIN_FILENO, &oldTerm) failed"; - newTerm = oldTerm; + struct termios newTerm = oldTerm; newTerm.c_lflag &= (tcflag_t) ~(ICANON | ECHO); - if(tcsetattr(fin, TCSANOW, &newTerm) == -1) - return "tcsetattr(STDIN_FILENO, TCSANOW, &newTerm)"; + if(tcsetattr(fin, TCSAFLUSH, &newTerm) == -1) + return "tcsetattr(STDIN_FILENO, TCSAFLUSH, &newTerm)"; ffWriteFDData(fout, strlen(request), request); - //Give the terminal 35ms to respond + //Give the terminal some time to respond if(poll(&(struct pollfd) { .fd = fin, .events = POLLIN }, 1, FF_IO_TERM_RESP_WAIT_MS) <= 0) { tcsetattr(fin, TCSANOW, &oldTerm);