mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-03 01:40:17 -05:00
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.
This commit is contained in:
parent
275b62371f
commit
f42e42246f
2 changed files with 10 additions and 4 deletions
|
|
@ -42,6 +42,7 @@
|
||||||
* OSC-4/104 out-of-bounds accesses to the color table. This was the
|
* OSC-4/104 out-of-bounds accesses to the color table. This was the
|
||||||
reason pywal turned foot windows transparent
|
reason pywal turned foot windows transparent
|
||||||
(https://codeberg.org/dnkl/foot/issues/434).
|
(https://codeberg.org/dnkl/foot/issues/434).
|
||||||
|
* PTY not being drained when the client application terminates.
|
||||||
|
|
||||||
|
|
||||||
### Security
|
### Security
|
||||||
|
|
|
||||||
13
terminal.c
13
terminal.c
|
|
@ -230,15 +230,20 @@ fdm_ptmx(struct fdm *fdm, int fd, int events, void *data)
|
||||||
uint8_t buf[24 * 1024];
|
uint8_t buf[24 * 1024];
|
||||||
ssize_t count = sizeof(buf);
|
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);
|
xassert(pollin);
|
||||||
count = read(term->ptmx, buf, sizeof(buf));
|
count = read(term->ptmx, buf, sizeof(buf));
|
||||||
|
|
||||||
if (count < 0) {
|
if (count < 0) {
|
||||||
if (errno == EAGAIN)
|
if (errno == EAGAIN || errno == EIO) {
|
||||||
return true;
|
/*
|
||||||
|
* 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");
|
LOG_ERRNO("failed to read from pseudo terminal");
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue