From arnej@math.ntnu.no  Fri Sep 19 14:40:21 1997
Received: from romberg.math.ntnu.no (153@romberg.imf.unit.no [129.241.15.150])
          by hub.freebsd.org (8.8.7/8.8.7) with SMTP id OAA11059
          for <FreeBSD-gnats-submit@freebsd.org>; Fri, 19 Sep 1997 14:40:18 -0700 (PDT)
Received: (qmail 12319 invoked from network); 19 Sep 1997 21:40:14 -0000
Received: from frida.math.ntnu.no (129.241.15.136)
  by romberg.imf.unit.no with SMTP; 19 Sep 1997 21:40:14 -0000
Received: (from arnej@localhost)
          by frida.math.ntnu.no (8.8.7/8.8.4)
	  id XAA21866; Fri, 19 Sep 1997 23:40:13 +0200 (MEST)
Message-Id: <199709192140.XAA21866@frida.math.ntnu.no>
Date: Fri, 19 Sep 1997 23:40:13 +0200 (MEST)
From: arnej@math.ntnu.no
Reply-To: arnej@math.ntnu.no
To: FreeBSD-gnats-submit@freebsd.org
Subject: termcap search fails too early
X-Send-Pr-Version: 3.2

>Number:         4585
>Category:       bin
>Synopsis:       termcap search fails too early
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    imp
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Sep 19 14:50:00 PDT 1997
>Closed-Date:    Sat Mar 20 20:46:36 MST 1999
>Last-Modified:  Sat Mar 20 20:47:02 MST 1999
>Originator:     Arne Henrik Juul
>Release:        FreeBSD 2.2-STABLE i386
>Organization:
Norwegian University of Technology and Science
>Environment:

	

>Description:

	The routines to find termcap entries (ultimately ending
	up in getent in libc) has problems if it has problems
	opening your ~/.termcap; only ENOENT is ignored.  But
	there may be other reasons why this fails and it should
	proceed to try /usr/share/misc/termcap; we got the problem
	when xterm couldn't access the home directory (because
	xterm is suid root, the home directory was on NFS without
	root privs, and was mod 700).  Other failure modes could
	probably be found as well.

>How-To-Repeat:

	Have a home directory on NFS, mounted without root privs,
	mode 700, then try starting xterm.  You should get the
	rather obscure message "unable to find usable termcap entry."

>Fix:
	
Patch from NetBSD:

Index: src/lib/libc/gen/getcap.c
===================================================================
RCS file: /usr/cvs/src/lib/libc/gen/getcap.c,v
retrieving revision 1.4
diff -u -r1.4 getcap.c
--- getcap.c	1995/10/22 14:36:15	1.4
+++ getcap.c	1997/09/19 21:26:27
@@ -269,10 +269,7 @@
 				fd = open(*db_p, O_RDONLY, 0);
 				if (fd < 0) {
 					/* No error on unfound file. */
-					if (errno == ENOENT)
-						continue;
-					free(record);
-					return (-2);
+					continue;
 				}
 				myfd = 1;
 			}
>Release-Note:
>Audit-Trail:

From: j@uriah.heep.sax.de (J Wunsch)
To: arnej@math.ntnu.no
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: bin/4585: termcap search fails too early
Date: Sat, 20 Sep 1997 13:19:43 +0200

 As arnej@math.ntnu.no wrote:
 
 > Patch from NetBSD:
 > 
 > Index: src/lib/libc/gen/getcap.c
 > ===================================================================
 > RCS file: /usr/cvs/src/lib/libc/gen/getcap.c,v
 > retrieving revision 1.4
 > diff -u -r1.4 getcap.c
 > --- getcap.c	1995/10/22 14:36:15	1.4
 > +++ getcap.c	1997/09/19 21:26:27
 > @@ -269,10 +269,7 @@
 >  				fd = open(*db_p, O_RDONLY, 0);
 >  				if (fd < 0) {
 >  					/* No error on unfound file. */
 > -					if (errno == ENOENT)
 > -						continue;
 > -					free(record);
 > -					return (-2);
 > +					continue;
 >  				}
 >  				myfd = 1;
 >  			}
 
 Why would it be wrong to make it continue only in the ENOENT and
 EACCES?  Maybe ELOOP, too.  Something like EMFILE or ENFILE should for
 sure be treated as an error in the first place.
 
 -- 
 cheers, J"org
 
 joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE
 Never trust an operating system you don't have sources for. ;-)

From: "Arne Henrik Juul" <arnej@math.ntnu.no>
To: joerg_wunsch@uriah.heep.sax.de (Joerg Wunsch)
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: bin/4585: termcap search fails too early
Date: Wed, 24 Sep 1997 23:32:37 +0200

 On Sep 20, 13:19, J Wunsch wrote:
 > Why would it be wrong to make it continue only in the ENOENT and
 > EACCES?  Maybe ELOOP, too.  Something like EMFILE or ENFILE should for
 > sure be treated as an error in the first place.
 
 For simplicity, I think just continuing is best; if there's a
 "permanent" error like EMFILE it will happen again on the next
 file tried so the correct error code will get returned.  On
 Solaris open(2) lists 20 possible error codes, and the only ones
 where I can see a real advantage in returning the error without
 trying the other possible pathnames are EFAULT and ENAMETOOLONG,
 all the others are either "there was something wrong with this
 pathname but one of the others could be better" or "some resource
 shortage which most probably will happen again with the same
 errno on the other pathnames".
 
 Of course, my immediate problem would be solved by just adding
 EACCES, but I'd hate to leave even more rare instances of this
 problem for later. (Like EISDIR or maybe ENXIO?)  Especially since
 this is a general routine (not just for termcap) which might be
 used in more demanding circumstances, and I think it desirable to have
 the rules as simple as possible.  It's not a very big matter to
 me however.
 
   -  Arne H. J.
 (sorry for my late answer)
Responsible-Changed-From-To: freebsd-bugs->imp 
Responsible-Changed-By: imp 
Responsible-Changed-When: Wed Sep 16 15:28:06 MDT 1998 
Responsible-Changed-Why:  
Looks like a slam dunk, I'll fix this. 
State-Changed-From-To: open->closed 
State-Changed-By: imp 
State-Changed-When: Sat Mar 20 20:46:36 MST 1999 
State-Changed-Why:  
I fixed this. 
>Unformatted:
