From MailHub.Postmaster@disney.com  Tue Dec  5 11:16:46 2000
Return-Path: <MailHub.Postmaster@disney.com>
Received: from mail.disney.com (mail.disney.com [204.128.192.15])
	by hub.freebsd.org (Postfix) with ESMTP id D5C5137B402
	for <FreeBSD-gnats-submit@freebsd.org>; Tue,  5 Dec 2000 11:16:45 -0800 (PST)
Received: from pain10.corp.disney.com (root@pain10.corp.disney.com [153.7.110.100])
	by mail.disney.com (Switch-2.0.1/Switch-2.0.1) with SMTP id eB5JGcp06283
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 5 Dec 2000 11:16:39 -0800 (PST)
Received: from louie.fa.disney.com by pain.corp.disney.com with ESMTP for FreeBSD-gnats-submit@freebsd.org; Tue, 5 Dec 2000 11:17:23 -0800
Received: from plio.fan.fa.disney.com (plio.fan.fa.disney.com [153.7.118.2])
	by louie.fa.disney.com (8.9.2/8.9.2) with ESMTP id LAA27656
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 5 Dec 2000 11:16:43 -0800 (PST)
	(envelope-from root@snoopy.fan.fa.disney.com)
Received: from snoopy.fan.fa.disney.com (snoopy.fan.fa.disney.com [153.7.117.170])
	by plio.fan.fa.disney.com (8.9.2/8.9.2) with ESMTP id LAA05477
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 5 Dec 2000 11:16:43 -0800 (PST)
	(envelope-from root@snoopy.fan.fa.disney.com)
Received: (from root@localhost)
	by snoopy.fan.fa.disney.com (8.11.1/8.9.3) id eB5JGr169436;
	Tue, 5 Dec 2000 11:16:54 -0800 (PST)
	(envelope-from root@snoopy.fan.fa.disney.com)
Message-Id: <200012051916.eB5JGr169436@snoopy.fan.fa.disney.com>
Date: Tue, 5 Dec 2000 11:16:54 -0800 (PST)
From: Jim.Pirzyk@disney.com
Sender: MailHub.Postmaster@disney.com
Reply-To: Jim.Pirzyk@disney.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: make assumes readdir return '.' and '..' first
X-Send-Pr-Version: 3.2

>Number:         23300
>Category:       bin
>Synopsis:       make assumes readdir returns '.' and '..' for the first two calls.
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    will
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Dec 05 11:20:02 PST 2000
>Closed-Date:    Sun Feb 25 02:11:25 PST 2001
>Last-Modified:  Sun Feb 25 02:12:16 PST 2001
>Originator:     Jim Pirzyk
>Release:        FreeBSD 4.2-RELEASE i386
>Organization:
>Environment:

	the /usr/src tree mounted over NFS from an SGI IRIX server running XFS.

>Description:

	The readdir on a specific NFS dir will not return '.' and '..' 
	as the first entries.  Make assumes that the first two calls to
	readdir will return those.  The make fails because it cannot find
	the file 'S' (which is returned second, see below)

>How-To-Repeat:

	Running this short C program shows that '.' and '..' are not the
	first two entries returned by readdir.


--- listdir.c ---

#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>

void main (int argc, char *argv[]) {
	int i;

	for (i = 1; i < argc; i++) {
		(void)list_files (argv[i]);
	}
}

void list_files (char *dir) {
	DIR *d = opendir (dir);
	struct dirent *dp;

	if ( d ) {
		while (dp=readdir(d)) {
			printf ("%s\n", dp->d_name);
		}
	} else {
		printf ("Could not open %s\n", dir);
	}

	closedir(dir);
}

--- output from listdir (run by ./listdir /usr/src/contrib/groff/devX100 ) ---

.
S
..
CB
CI
CR
HB
HI
HR
NB
NI
NR
TB
TI
TR
CBI
HBI
NBI
TBI
DESC

>Fix:

*** ./usr.bin/make/dir.c.orig	Tue Dec  5 10:54:57 2000
--- ./usr.bin/make/dir.c	Tue Dec  5 11:05:40 2000
***************
*** 1060,1067 ****
--- 1060,1069 ----
  	    /*
  	     * Skip the first two entries -- these will *always* be . and ..
  	     */
+ /*
  	    (void)readdir(d);
  	    (void)readdir(d);
+ */
  
  	    while ((dp = readdir (d)) != (struct dirent *) NULL) {
  #if defined(sun) && defined(d_ino) /* d_ino is a sunos4 #define for d_fileno */
***************
*** 1074,1079 ****
--- 1076,1093 ----
  		    continue;
  		}
  #endif /* sun && d_ino */
+ 
+ 		/*
+ 		 * Skip the '.' and '..' entries, XFS over NFS filesystems
+ 		 * since SGI does not guarentee that '.' and '..' are the
+ 		 * first two entries returned from readdir().
+ 		 */
+ 		if (dp->d_name[0] == '.' && 
+ 			(dp->d_name[1] == NULL || 
+ 			(dp->d_name[1] == '.' && dp->d_name[2] == NULL))) {
+ 			continue;
+ 		}
+ 
  		(void)Hash_CreateEntry(&p->files, dp->d_name, (Boolean *)NULL);
  	    }
  	    (void) closedir (d);


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->will 
Responsible-Changed-By: jedgar 
Responsible-Changed-When: Wed Dec 6 03:52:44 PST 2000 
Responsible-Changed-Why:  
Over to maintainer 

http://www.freebsd.org/cgi/query-pr.cgi?pr=23300 
State-Changed-From-To: open->suspended 
State-Changed-By: will 
State-Changed-When: Mon Dec 25 23:36:19 PST 2000 
State-Changed-Why:  
Merged into -CURRENT, where it will sit out for at least six weeks, since 
I don't have access to an environment like the one you describe (and thus 
your listdir program doesn't work the same way).  I accepted your patch, 
however, because it appears to work correctly. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=23300 
State-Changed-From-To: suspended->closed 
State-Changed-By: will 
State-Changed-When: Sun Feb 25 02:11:25 PST 2001 
State-Changed-Why:  
Hmm, thought I closed this PR.  Anyway, the fixed was MFC'd to RELENG_4 
and RELENG_3 almost two weeks ago. 

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