Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix: Basic REPL hangs when ioctls can't be written to TTY.
16 changes: 16 additions & 0 deletions Modules/readline.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <signal.h> // SIGWINCH
#include <stdlib.h> // free()
#include <string.h> // strdup()
#include <termios.h> // termios, tcgetattr(), tcsetattr()
#include <unistd.h> // isatty(), STDIN_FILENO
#ifdef HAVE_SYS_SELECT_H
# include <sys/select.h> // select()
#endif
Expand Down Expand Up @@ -1645,6 +1647,20 @@ PyInit_readline(void)
if (mod_state == NULL){
goto error;
}

// gh-139027: If tcsetattr fails do not initialize readline and err it
if (isatty(STDIN_FILENO)) {
struct termios original_tty;
if (tcgetattr(STDIN_FILENO, &original_tty) == 0) {
struct termios test_tty = original_tty;
if (tcsetattr(STDIN_FILENO, TCSANOW, &test_tty) != 0) {
PyErr_SetString(PyExc_OSError,
"termios failure (Operation not permitted)");
goto error;
}
}
}

PyOS_ReadlineFunctionPointer = call_readline;
if (setup_readline(mod_state) < 0) {
PyErr_NoMemory();
Expand Down
Loading