diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2021-04-07 17:09:31 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2021-04-07 17:09:31 +0000 |
| commit | fb4066f94e0b6a05c429d12ca75690a4d5c5a078 (patch) | |
| tree | ee33150d1db1781ebb5a7b33f8410bdf96c21436 /terminal.c | |
| parent | sixel: unhook: tighten up the condition needed for us to free image data pre-maturely (diff) | |
terminal: drain PTY when client terminates
This is done by:
* Not limiting the number of times we try to read from the PTY when
we’ve have POLLHUP
* Not requiring the entire the previous read to have filled our
buffer.
* Not erroring out on EIO.
Diffstat (limited to 'terminal.c')
| -rw-r--r-- | terminal.c | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -230,15 +230,20 @@ fdm_ptmx(struct fdm *fdm, int fd, int events, void *data) uint8_t buf[24 * 1024]; ssize_t count = sizeof(buf); - const size_t max_iterations = 10; + const size_t max_iterations = !hup ? 10 : (size_t)-1ll; - for (size_t i = 0; i < max_iterations && pollin && count == sizeof(buf); i++) { + for (size_t i = 0; i < max_iterations && pollin; i++) { xassert(pollin); count = read(term->ptmx, buf, sizeof(buf)); if (count < 0) { - if (errno == EAGAIN) - return true; + if (errno == EAGAIN || errno == EIO) { + /* + * EAGAIN: no more to read - FDM will trigger us again + * EIO: assume PTY was closed - we already have, or will get, a EPOLLHUP + */ + break; + } LOG_ERRNO("failed to read from pseudo terminal"); return false; |
