Handle ioctl failures when resizing the tty more gracefully

This commit is contained in:
Kovid Goyal 2017-09-07 18:29:23 +05:30
parent d5d812ccfe
commit 7dc51d7d9e
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -338,6 +338,18 @@ mark_for_close(ChildMonitor *self, PyObject *args) {
Py_RETURN_NONE;
}
static inline bool
pty_resize(int fd, struct winsize *dim) {
while(true) {
if (ioctl(fd, TIOCSWINSZ, dim) == -1) {
if (errno == EINTR) continue;
if (errno != EBADF && errno != ENOTTY) return false;
}
break;
}
return true;
}
static PyObject *
resize_pty(ChildMonitor *self, PyObject *args) {
#define resize_pty_doc "Resize the pty associated with the specified child"
@ -349,7 +361,7 @@ resize_pty(ChildMonitor *self, PyObject *args) {
for (size_t i = 0; i < self->count; i++) {
if (children[i].id == window_id) {
found = Py_True;
if (ioctl(fds[EXTRA_FDS + i].fd, TIOCSWINSZ, &dim) == -1) PyErr_SetFromErrno(PyExc_OSError);
if (!pty_resize(children[i].fd, &dim)) PyErr_SetFromErrno(PyExc_OSError);
break;
}
}