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

Re: zsh exits after delete-char-or-list and two ^Cs



Danek Duvall wrote:
> This happens with 4.0.6, 4.2.0 and 4.2.1, the first two on Linux, the
> latter on Solaris.  If I use delete-char-or-list, then hit control-C twice,
> the first time cancels the command-line where I hit ^D, and the second one
> exits the shell.

Obviously if I tried to look at this today after my holiday it would
just get me all frustrated.  So that would be a bad idea.

Here's a patch.  The problem is that there's a special test to see if
there was an EOF character (which must be ^D for the bug to turn up in
this particular form) at the start of the line.  This test was
erroneously triggered on the second ^C as the input character hadn't
changed from the ^D used to list completion.  The first ^C didn't
trigger it because the line hadn't yet been emptied.  The functions
don't pass back the state properly, so it's difficult to check what
actually happened (i.e. EOF or interrupt); maybe it can be done better
than this.

Note that errflag isn't set at the point of the patch if there was a ^C.
This seems to be deliberate; see the handling of EINTR in getkey().  I
think it's also to do with the lack of distinction between an
interruption and an EOF---in loop(), we exit the command loop, and
hence the shell, if we get an end-of-input token and errflag is *not* set.

I thought about resetting lastchar at the start of each line.  However,
I think there are cases where that doesn't work.

Index: Src/Zle/zle_main.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_main.c,v
retrieving revision 1.49
diff -u -r1.49 zle_main.c
--- Src/Zle/zle_main.c	13 Jul 2004 09:41:37 -0000	1.49
+++ Src/Zle/zle_main.c	1 Sep 2004 17:15:15 -0000
@@ -687,12 +687,19 @@
 	reselectkeymap();
 	selectlocalmap(NULL);
 	bindk = getkeycmd();
-	if (!ll && isfirstln && !(zlereadflags & ZLRF_IGNOREEOF) &&
-	    lastchar == eofchar) {
-	    eofsent = 1;
-	    break;
-	}
 	if (bindk) {
+	    if (!ll && isfirstln && !(zlereadflags & ZLRF_IGNOREEOF) &&
+		lastchar == eofchar) {
+		/*
+		 * Slight hack: this relies on getkeycmd returning
+		 * a value for the EOF character.  However,
+		 * undefined-key is fine.  That's necessary because
+		 * otherwise we can't distinguish this case from
+		 * a ^C.
+		 */
+		eofsent = 1;
+		break;
+	    }
 	    if (execzlefunc(bindk, zlenoargs))
 		handlefeep(zlenoargs);
 	    handleprefixes();

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************



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