zsh-workers
 help / color / mirror / code / Atom feed
From: Roman Perepelitsa <roman.perepelitsa@gmail.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: PATCH: bug fix: infinite loop when tty disappears
Date: Fri, 27 Sep 2019 14:05:34 +0200	[thread overview]
Message-ID: <CAN=4vMpU1pExCMOodC1PEWrLaCFDB8-YJG1CHpyEJ2zyY27Vkg@mail.gmail.com> (raw)

[-- 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

                 reply	other threads:[~2019-09-27 12:06 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAN=4vMpU1pExCMOodC1PEWrLaCFDB8-YJG1CHpyEJ2zyY27Vkg@mail.gmail.com' \
    --to=roman.perepelitsa@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).