Fail early when opening tty fails

This commit is contained in:
Kovid Goyal 2018-09-02 14:29:10 +05:30
parent e05aaf77ce
commit ac686a47c1
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -126,6 +126,7 @@ open_tty(PyObject *self UNUSED, PyObject *args) {
if (!read_with_timeout) flags |= O_NONBLOCK; if (!read_with_timeout) flags |= O_NONBLOCK;
static char ctty[L_ctermid+1]; static char ctty[L_ctermid+1];
int fd = open(ctermid(ctty), flags); int fd = open(ctermid(ctty), flags);
if (fd == -1) { PyErr_SetFromErrno(PyExc_OSError); return NULL; }
struct termios *termios_p = calloc(1, sizeof(struct termios)); struct termios *termios_p = calloc(1, sizeof(struct termios));
if (!termios_p) return PyErr_NoMemory(); if (!termios_p) return PyErr_NoMemory();
if (tcgetattr(fd, termios_p) != 0) { free(termios_p); PyErr_SetFromErrno(PyExc_OSError); return NULL; } if (tcgetattr(fd, termios_p) != 0) { free(termios_p); PyErr_SetFromErrno(PyExc_OSError); return NULL; }