Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: bug fix: infinite loop when tty disappears
- X-seq: zsh-workers 44784
- From: Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: PATCH: bug fix: infinite loop when tty disappears
- Date: Fri, 27 Sep 2019 14:05:34 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=oZQ57C2No17eswfAWV/1kvmj0BITRe1JY57j9H9+vJ8=; b=K0Hid6uKGf9GgCRQlQ0H9ucv8KrbjK//JDi13WbBM7KIvNZj7eHMSBiKB+kPdETWNH 2m0naokyPRcwy0DxmEmd2qGYOr5YUPQa7mxZ/8ZEJu6LoyTVngjXtwPIO9CX51iqkHJq z/WHXoXxYHjRHwMt+eLJZu1RxASWDdtwS3Q7mAvTLy+hqA00pD44JOYEdndHOQM11DN4 fm5o7jEuETnujpibgnznrDtHI2zhMPB2/8baIHFuzheborQoDTpC7kLazSVgEhaNG76I jdEI9eVrMWROb837OTxuIIiXjqqoFmDfkg5X63/B1dyAfsR+ZQWTWNVHQyfs+ouKho+d 8Scw==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
When TTY disappears and there is at least one fd watcher,
raw_getbyte() can enter an infinite loop where it keeps calling poll()
over and over again.
To reproduce, open a terminal, start zsh and type this:
rm -f /tmp/fifo
mkfifo /tmp/fifo
exec 3<>/tmp/fifo
do-nothing() {}
zle -F 3 do-nothing
Then make TTY disappear. For example, kill the parent with `kill -9
$PPID` and close the terminal window if it's still there. Observe that
zsh is consuming 100% CPU. Note that do-nothing() never gets called.
This patch makes the poll() loop in raw_getbyte() terminate when TTY
is signalling POLLHUP. This makes the behavior consistent with the
case where TTY disappears while no fd watchers are installed.
Roman.
diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index d3b9aeab8..22c12cf1f 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -708,7 +708,7 @@ raw_getbyte(long do_keytmout, char *cptr, int full)
*/
if (
# ifdef HAVE_POLL
- (fds[0].revents & POLLIN)
+ (fds[0].revents & (POLLIN|POLLERR|POLLHUP|POLLNVAL))
# else
FD_ISSET(SHTTY, &foofd)
# endif
Messages sorted by:
Reverse Date,
Date,
Thread,
Author