From 7dc51d7d9e5305e71bc34c089bb459d9be7ea742 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 7 Sep 2017 18:29:23 +0530 Subject: [PATCH] Handle ioctl failures when resizing the tty more gracefully --- kitty/child-monitor.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/kitty/child-monitor.c b/kitty/child-monitor.c index f71dfdb89..3334f6544 100644 --- a/kitty/child-monitor.c +++ b/kitty/child-monitor.c @@ -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; } }