Subject: bin/35904: Odd behaviour of ksh in emacs mode
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org>
From: None <joerg.bsd@internode.net.au>
List: netbsd-bugs
Date: 03/03/2007 04:50:00
>Number:         35904
>Category:       bin
>Synopsis:       Odd behaviour of ksh in emacs mode
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Mar 03 04:50:00 +0000 2007
>Originator:     Joerg Niendorf
>Release:        Revision 1.31 of src/bin/ksh/emacs.c
>Organization:
none
>Environment:
N/A

>Description:
If NetBSD's in-tree ksh is used with the emacs inline editor, exiting
from a subshell through Ctrl-D prints the new prompt on the same line
as the old prompt, i.e.:

$ echo $KSH_VERSION
@(#)PD KSH v5.2.14 99/07/13.2
$ su
Password:
# set -o emacs
#

When I hit Ctrl-D at this point, the resulting output is:

# $ _


Of course, depending on the contents of the environment variable PS1,
the output can look even weirder. For instance:

root@pri.jn # /home/joerg/netbsd $ _


Hitting Enter "fixes" this immediately, but it shouldn't be like that.

>How-To-Repeat:
Please refer to the above problem description.

>Fix:
This bug was fixed in OpenBSD by Otto Moerbeek two years ago:

http://www.openbsd.org/cgi-bin/cvsweb/src/bin/ksh/emacs.c.diff?r1=1.34&r2=1.35&f=h

I compiled NetBSD's ksh with Otto's fix and it works fine. The behaviour
when using the emacs inline editor is now identical to the behaviour
when using the vi inline editor. That is, given the above example, the
output would now be:

# ^D
$ _


So, I think it would be a good idea to integrate Otto's fix into
NetBSD's ksh also:

Index: emacs.c
===================================================================
RCS file: /cvsroot/src/bin/ksh/emacs.c,v
retrieving revision 1.31
diff -b -u -r1.31 emacs.c
--- emacs.c	13 May 2006 21:58:51 -0000	1.31
+++ emacs.c	3 Mar 2007 01:10:17 -0000
@@ -861,6 +861,10 @@
 x_end_of_text(c)
 	int c;
 {
+	x_zotc(edchars.eof);
+	x_putc('\r');
+	x_putc('\n');
+	x_flush();
 	return KEOL;
 }