Subject: bin/23175: sh(1) and editline(3) don't play together if using unknown $TERM
To: None <gnats-bugs@gnats.netbsd.org>
From: None <lukem@NetBSD.org>
List: netbsd-bugs
Date: 10/17/2003 16:59:54
>Number:         23175
>Category:       bin
>Synopsis:       sh(1) and editline(3) don't play together if using unkonwn $TERM
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Oct 17 07:00:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Luke Mewburn
>Release:        NetBSD 1.6ZC
>Organization:
>Environment:
System: NetBSD argo.mewburn.net 1.6ZC NetBSD 1.6ZC (ARGO from GENERIC-$Revision: 1.570 $) #3: Thu Sep 25 18:27:41 EST 2003 lukem@argo.mewburn.net:/var/obj/i386/usr/src/sys/arch/i386/compile/ARGO i386
Architecture: i386
Machine: i386
>Description:
	If sh(1) is started with an unknown $TERM, and then it's set
	to something that is known, "set -o emacs" still complains with
		No entry for terminal type "vt100";
		using dumb terminal settings.

	This is because 'set -o (emacs|vi)' calls el_init(3).
	el_init(3) calls the editline(3) internal function
	term_init() which then calls term_set(el, NULL),
	which uses getenv("TERM") to get the terminal type.
	However, setting $TERM in the shell doesn't set
	$TERM in the shell's setenv(3) environment, so el_init(3)
	gets the wrong terminal type.

>How-To-Repeat:
	env -i TERM=blah sh
	$ set -o emacs
	No entry for terminal type "blah";
	using dumb terminal settings.
	$ ^D

	env -i TERM=blah sh
	$ export TERM=vt100
	$ echo $TERM
	vt100
	$ set -o emacs
	No entry for terminal type "blah";
	using dumb terminal settings.

>Fix:
	The following patch seems to Do The Right Thing.
	I'd like someone (hi christos@ ;-) to sanity check this
	before commit.

Index: histedit.c
===================================================================
RCS file: /cvsroot/wasabisrc/src/bin/sh/histedit.c,v
retrieving revision 1.1.1.4
diff -p -p -u -r1.1.1.4 histedit.c
--- histedit.c	9 Oct 2003 01:30:50 -0000	1.1.1.4
+++ histedit.c	17 Oct 2003 06:49:21 -0000
@@ -105,6 +105,8 @@ histedit(void)
 			/*
 			 * turn editing on
 			 */
+			char *term;
+
 			INTOFF;
 			if (el_in == NULL)
 				el_in = fdopen(0, "r");
@@ -117,6 +119,11 @@ histedit(void)
 			if (tracefile)
 				el_err = tracefile;
 #endif
+			term = lookupvar("TERM");
+			if (term)
+				setenv("TERM", term, 1);
+			else
+				unsetenv("TERM");
 			el = el_init(arg0, el_in, el_out, el_err);
 			if (el != NULL) {
 				if (hist)
>Release-Note:
>Audit-Trail:
>Unformatted: