Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Infinite loop on exit

On Thu, 10 Sep 2015 07:25:10 -0700
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> Did someone fix Mikael's infinite-PS2-on-exit issue from 36407?

No, it got tacked on to a thread about something else, so got missed.

It was this:

> zle -f
> % bindkey 0 e
> % e() exit
> % zle -N e
> % '
> quote> 0
> this prints the PS2 prompt indefinitely, ctrl-c is ignored

exit_pending is set because we need to tidy up functions before we exit.
To avoid going insane, we only recover at the top level (sanitising the
chain of checks to optimise this so we could exit earlier would be
pretty gruesome and gain almost nothing).  In that case we shouldn't try
and read another character to prevent us getting there.

The following works here and looks unobjectionable.  Flagging an error
is mostly to prevent another error message from appearing when the lexer
finds out its plans have gone agley.

This doesn't do anything special with ^C, but I think that was just down
to Zle being rather special with interrupts, so if we don't go back into
it repeatedly the issue doesn't arise.


diff --git a/Src/hist.c b/Src/hist.c
index 75e809c..9c42d85 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -390,6 +390,12 @@ ihgetc(void)
     int c = ingetc();
+    if (exit_pending)
+    {
+	lexstop = 1;
+	errflag |= ERRFLAG_ERROR;
+	return ' ';
+    }
     qbang = 0;
     if (!stophist && !(inbufflags & INP_ALIAS)) {
 	/* If necessary, expand history characters. */

Messages sorted by: Reverse Date, Date, Thread, Author