From daniel@bsd.diefree.com  Wed Dec 17 18:53:17 2003
Return-Path: <daniel@bsd.diefree.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 164CD16A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 17 Dec 2003 18:53:17 -0800 (PST)
Received: from bsd.diefree.com (c-24-6-31-57.client.comcast.net [24.6.31.57])
	by mx1.FreeBSD.org (Postfix) with SMTP id 3874D43D31
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 17 Dec 2003 18:53:15 -0800 (PST)
	(envelope-from daniel@bsd.diefree.com)
Received: (qmail 19796 invoked from network); 18 Dec 2003 02:54:35 -0000
Received: from localhost (HELO bsd.diefree.com) (127.0.0.1)
  by localhost with SMTP; 18 Dec 2003 02:54:35 -0000
Received: (from root@localhost)
	by bsd.diefree.com (8.12.10/8.12.10/Submit) id hBI2sYDO019792;
	Wed, 17 Dec 2003 18:54:34 -0800 (PST)
	(envelope-from daniel)
Message-Id: <200312180254.hBI2sYDO019792@bsd.diefree.com>
Date: Wed, 17 Dec 2003 18:54:34 -0800 (PST)
From: Daniel Hulme <d@diefree.com>
Reply-To: Daniel <d@diefree.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc: d@diefree.com
Subject: [PATCH] buildworld fails in sysinstall if terminfo database in /usr/share/misc/terminfo	
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         60352
>Category:       misc
>Synopsis:       [patch] buildworld fails in sysinstall if terminfo database in /usr/share/misc/terminfo
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    antoine
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Dec 17 19:00:34 PST 2003
>Closed-Date:    Tue May 06 11:51:38 UTC 2008
>Last-Modified:  Tue May 06 11:51:38 UTC 2008
>Originator:     Daniel Hulme <d@diefree.com>
>Release:        FreeBSD 5.2-RC i386
>Organization:
None
>Environment:
System: FreeBSD bsd.diefree.com 5.2-RC FreeBSD 5.2-RC #1: Mon Dec 15 14:12:25 PST 2003 daniel@bsd.diefree.com:/usr/obj/usr/src/sys/kernel_pf i386
(this is my current kernel, the problem occurs on 5.2-RC vanilla as well)

>Description:
The compilation of [/usr/src/usr.sbin/sysinstall] depends on a small
program called "rtermcap".  The program is used to generate a file
called "makedevs.c" from several termcap entries (ansi, xterm, cons25,
etc.).

rtermcap, in turn, relies on a c call (ncurses) to "tgetent," which
checks for a termcap entry, and fills a buffer with the terminal
information.  On closer inspection, however, "tgetent" is also capable
of using terminfo, and in fact prefers terminfo over termcap (if the
terminal exists in terminfo, it will never check termcap--perhaps this
behavior can be changed in ncurses, but I'm not sure it should be).
Unfortunately, it acts a little differently when using terminfo:

[man curs_termcap]
The tgetent routine loads the entry for name.  It returns 1 on success,
0 if there is no such entry, and -1 if the terminfo database could  not
be found.  The emulation ignores the buffer pointer bp.

So, in the event that a terminfo database is present, tgetent will use
it, and will not fill the buffer.  However, the Makefile in
[/usr/src/usr.sbin/sysinstall] relies on the buffer being filled, so it
can use this data to create the arrays in makedevs.c.  There is no
detection of this issue currently, and the compilation of sysinstall
fails with the following message(s), due to the arrays being empty:

	makedevs.c:4: error: syntax error before ',' token
	makedevs.c:7: error: syntax error before ',' token
	makedevs.c:10: error: syntax error before ',' token
	makedevs.c:13: error: syntax error before ',' token
	makedevs.c:16: error: syntax error before ',' token
	makedevs.c:19: error: syntax error before ',' token
	makedevs.c:22: error: syntax error before ',' token
	makedevs.c:25: error: syntax error before ',' token
	makedevs.c:28: error: syntax error before ',' token
	makedevs.c:31: error: syntax error before ',' token 
>How-To-Repeat:
[Install linux compat]

[Link linux terminfo database to /usr/share/misc]
ln -s /usr/compat/linux/usr/share/terminfo /usr/share/misc/

[note that any method of installing a valid terminfo where ncurses will find it should be sufficient]

[Compile sysinstall]
cd /usr/src/usr.sbin/sysinstall/
make clean
make

[Watch the errors]
>Fix:

--- patch-rtermcap.c begins here ---
--- rtermcap_orig.c	Sun May  7 15:07:53 1995
+++ rtermcap.c	Wed Dec 17 18:31:21 2003
@@ -1,15 +1,23 @@
-#include <stdio.h>
-#include <termcap.h>
+#include <stdlib.h>
 
 int
 main(int argc, char **argv)
 {
-	char	buf[4096];
+	char * files[]={ "/etc/termcap" };
+	char * tbuf;
+	char * buf;
+	char * c;
+	char d;
 	int	i;
-
 	if (argc < 2)
 		return 1;
-	i = tgetent(buf, argv[1]);
-	printf("%s",buf);
+	i=cgetent(&tbuf, files, argv[1]);
+	for (c = tbuf; *c != 0; c++) {
+		if(*c != '\t' && (*c != 58 || d != 58)) { 
+			printf("%c", *c);
+			d = *c;
+		}
+	}
+	cgetclose();
 	return 0;
 }
--- patch-rtermcap.c ends here ---


>Release-Note:
>Audit-Trail:

From: Dan Hulme <d@diefree.com>
To: freebsd-gnats-submit@FreeBSD.org, d@diefree.com
Cc:  
Subject: Re: misc/60352: [PATCH] buildworld fails in sysinstall if terminfo
 database in /usr/share/misc/terminfo
Date: Thu, 18 Dec 2003 11:27:06 -0800

 By way of explanation, this code returns identical output as the 
 original rtermcap.c, except in the case of an existing terminfo.  In 
 that case, this code returns to correct output (i.e., the same as if 
 there were no terminfo db), whereas the old code failed silently 
 (printing nothing).
 
 The choice to strip double colons and tabs was made not by necessity (I 
 am not certain whether it is important or not, but I imagine the target 
 program would ignore them), but rather to produce identical output.  
 This way, there can be no doubt that this code should function as a 
 drop-in replacement for the old code.
 
 I tested this code and the resulting makedevs.c was identical in size 
 and content to that created with the original code.  Again, the only 
 difference is when a terminfo db exists, in which case *only* this code 
 works.
 
 -Dan
State-Changed-From-To: open->closed 
State-Changed-By: antoine 
State-Changed-When: Tue May 6 11:48:50 UTC 2008 
State-Changed-Why:  
Close: this problem has been solved in revision 1.133 of 
src/usr.sbin/sysinstall/Makefile (december 2004) 
by using the TERMCAP environment variable. 


Responsible-Changed-From-To: freebsd-bugs->antoine 
Responsible-Changed-By: antoine 
Responsible-Changed-When: Tue May 6 11:48:50 UTC 2008 
Responsible-Changed-Why:  
Track. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=60352 
>Unformatted:
