zsh-workers
 help / Atom feed
* PATCH: bug fix: infinite loop when tty disappears
@ 2019-09-27 12:05 Roman Perepelitsa
  0 siblings, 0 replies; 1+ messages in thread
From: Roman Perepelitsa @ 2019-09-27 12:05 UTC (permalink / raw)
  To: Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 731 bytes --]

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.

[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 394 bytes --]

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

^ permalink raw reply	[flat|nested] 1+ messages in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-27 12:05 PATCH: bug fix: infinite loop when tty disappears Roman Perepelitsa

zsh-workers

Archives are clonable: git clone --mirror http://inbox.vuxu.org/zsh-workers

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.workers


AGPL code for this site: git clone https://public-inbox.org/ public-inbox