aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-04-08 08:41:05 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-04-08 08:41:05 +0000
commit0af7916fcca243ab08942b32eae2b25c53f49b4a (patch)
tree5c00b8b35a2f1e7ebfa69cf0c369b52d0fef1a8c
parentci: build on alpine/latest, not edge (diff)
parentterminal: drain PTY when client terminates (diff)
Merge branch 'drain-pty-when-client-terminates'
-rw-r--r--CHANGELOG.md1
-rw-r--r--terminal.c13
2 files changed, 10 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9f0ed40f..46af71bd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -42,6 +42,7 @@
* OSC-4/104 out-of-bounds accesses to the color table. This was the
reason pywal turned foot windows transparent
(https://codeberg.org/dnkl/foot/issues/434).
+* PTY not being drained when the client application terminates.
### Security
diff --git a/terminal.c b/terminal.c
index b55a63a9..c6b4705c 100644
--- a/terminal.c
+++ b/terminal.c
@@ -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;