NetBSD Problem Report #42879

From yamt@NetBSD.org  Wed Feb 24 03:28:58 2010
Return-Path: <yamt@NetBSD.org>
Received: by www.NetBSD.org (Postfix, from userid 1270)
	id 52C0B63C49F; Wed, 24 Feb 2010 03:28:58 +0000 (UTC)
Message-Id: <20100224032858.52C0B63C49F@www.NetBSD.org>
Date: Wed, 24 Feb 2010 03:28:58 +0000 (UTC)
From: yamt@NetBSD.org
Reply-To: yamt@NetBSD.org
To: gnats-bugs@NetBSD.org
Subject: rewinddir(3) doesn't reset the stream
X-Send-Pr-Version: 3.95

>Number:         42879
>Category:       lib
>Synopsis:       rewinddir(3) doesn't reset the stream
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    yamt
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Feb 24 03:30:00 +0000 2010
>Closed-Date:    
>Last-Modified:  Mon Jul 30 02:30:03 +0000 2012
>Originator:     YAMAMOTO Takashi
>Release:        NetBSD-current
>Organization:

>Environment:

>Description:
	our rewinddir(3) doesn't reset the stream and following readdir
	returns cached entries in the case of __DTF_READALL.

	susv3 says:
		It shall also cause the directory stream to refer to the
		current state of the corresponding directory, as a call to
		opendir() would have done.

	it seems that subversion/apr depends on the resetting behaviour
	and produces "Can't read directory" errors.  (PR/40229)
	whatever workaround is done in subversion, our rewinddir should
	be fixed.
>How-To-Repeat:

>Fix:


>Release-Note:

>Audit-Trail:
From: YAMAMOTO Takashi <yamt@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/42879 CVS commit: src
Date: Sun, 26 Sep 2010 02:27:00 +0000

 Module Name:	src
 Committed By:	yamt
 Date:		Sun Sep 26 02:27:00 UTC 2010

 Modified Files:
 	src/include: dirent.h
 	src/lib/libc/gen: Makefile.inc closedir.c dirent_private.h opendir.c
 	    rewinddir.c
 Added Files:
 	src/lib/libc/gen: initdir.c

 Log Message:
 fix rewinddir on nfs.  fix PR/42879 (and probably PR/40229.)


 To generate a diff of this commit:
 cvs rdiff -u -r1.33 -r1.34 src/include/dirent.h
 cvs rdiff -u -r1.171 -r1.172 src/lib/libc/gen/Makefile.inc
 cvs rdiff -u -r1.15 -r1.16 src/lib/libc/gen/closedir.c
 cvs rdiff -u -r1.3 -r1.4 src/lib/libc/gen/dirent_private.h
 cvs rdiff -u -r0 -r1.1 src/lib/libc/gen/initdir.c
 cvs rdiff -u -r1.36 -r1.37 src/lib/libc/gen/opendir.c
 cvs rdiff -u -r1.12 -r1.13 src/lib/libc/gen/rewinddir.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: yamt@NetBSD.org
State-Changed-When: Tue, 05 Oct 2010 23:34:53 +0000
State-Changed-Why:
fixed.


From: yamt@mwd.biglobe.ne.jp (YAMAMOTO Takashi)
To: tshiozak@bsdclub.org
Cc: gnats-bugs@NetBSD.org
Subject: Re: PR/42879 CVS commit: src
Date: Mon, 23 May 2011 04:19:21 +0000 (UTC)

 hi,

 thanks.  i don't pretend to understand the libc/compat stuff. :-)

 > Hi,
 > 
 > This fix breaks compatibility for pre-3.0 binaries.
 > 
 > Here is a patch. (I don't know whether such __RENAME() usage is appropriate.)

 the problem is that, the compat version of opendir is calling the newer
 getdents via _initdir, right?

 does rewinddir have the same problem as well?

 YAMAMOTO Takashi

From: "T.SHIOZAKI" <tshiozak@bsdclub.org>
To: yamt@mwd.biglobe.ne.jp
Cc: gnats-bugs@NetBSD.org
Subject: Re: PR/42879 CVS commit: src
Date: Mon, 23 May 2011 17:46:45 +0900 (JST)

 > hi,
 > 
 > thanks.  i don't pretend to understand the libc/compat stuff. :-)
 > 
 > > Hi,
 > > 
 > > This fix breaks compatibility for pre-3.0 binaries.
 > > 
 > > Here is a patch. (I don't know whether such __RENAME() usage is appropriate.)
 > 
 > the problem is that, the compat version of opendir is calling the newer
 > getdents via _initdir, right?

 Yes.


 > does rewinddir have the same problem as well?

 Certainly.  I didn't notice it.


 ---
 Takuya SHIOZAKI

Responsible-Changed-From-To: lib-bug-people->yamt
Responsible-Changed-By: yamt@NetBSD.org
Responsible-Changed-When: Mon, 27 Jun 2011 01:21:05 +0000
Responsible-Changed-Why:
the fix i committed turned out to have a problem


State-Changed-From-To: closed->open
State-Changed-By: yamt@NetBSD.org
State-Changed-When: Mon, 27 Jun 2011 01:21:05 +0000
State-Changed-Why:
the fix i committed turned out to have a problem


From: David Holland <dholland-bugs@netbsd.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: lib/42879: rewinddir(3) doesn't reset the stream
Date: Mon, 8 Aug 2011 08:25:47 +0000

 this didn't get filed in gnats back in May.

    ------

 From: "T.SHIOZAKI" <tshiozak@bsdclub.org>
 To: yamt@NetBSD.org, lib-bug-people@NetBSD.org, gnats-admin@NetBSD.org,
 	netbsd-bugs@NetBSD.org
 Subject: Re: PR/42879 CVS commit: src
 Date: Mon, 16 May 2011 18:38:56 +0900 (JST)


 Hi,

 This fix breaks compatibility for pre-3.0 binaries.

 Here is a patch. (I don't know whether such __RENAME() usage is appropriate.)


 Index: lib/libc/compat/gen/Makefile.inc
 ===================================================================
 RCS file: /usr/home/cvs/NetBSD/src/lib/libc/compat/gen/Makefile.inc,v
 retrieving revision 1.14
 diff -u -r1.14 Makefile.inc
 --- lib/libc/compat/gen/Makefile.inc	12 Mar 2011 19:52:47 -0000	1.14
 +++ lib/libc/compat/gen/Makefile.inc	16 May 2011 08:44:57 -0000
 @@ -3,8 +3,9 @@
  .PATH: ${COMPATDIR}/gen
  SRCS+=compat_errlist.c compat_fts.c compat___fts13.c compat___fts30.c \
      compat___fts31.c compat_getmntinfo.c compat_glob.c compat___glob13.c \
 -    compat_opendir.c compat_readdir.c compat__readdir_unlocked30.c \
 -    compat_scandir.c compat_siglist.c compat_signame.c compat_sigsetops.c \
 +    compat_opendir.c compat_initdir.c compat_readdir.c \
 +    compat__readdir_unlocked30.c compat_scandir.c \
 +    compat_siglist.c compat_signame.c compat_sigsetops.c \
      compat_times.c compat_timezone.c compat_unvis.c compat_utmpx.c \
      compat__sys_errlist.c compat__sys_nerr.c compat__sys_siglist.c \
      compat_time.c compat_utime.c compat_devname.c compat_alphasort.c \
 Index: lib/libc/compat/include/dirent.h
 ===================================================================
 RCS file: /usr/home/cvs/NetBSD/src/lib/libc/compat/include/dirent.h,v
 retrieving revision 1.7
 diff -u -r1.7 dirent.h
 --- lib/libc/compat/include/dirent.h	24 Feb 2009 18:42:36 -0000	1.7
 +++ lib/libc/compat/include/dirent.h	16 May 2011 09:25:39 -0000
 @@ -51,6 +51,9 @@

  #if defined(_NETBSD_SOURCE)

 +int _initdir(DIR *, int, const char *);
 +int ___initdir60(DIR *, int, const char *);
 +
  struct dirent12 *_readdir_unlocked(DIR *, int);
  struct dirent *___readdir_unlocked50(DIR *, int);
  struct dirent *___readdir_unlocked30(DIR *);
 Index: lib/libc/gen/Makefile.inc
 ===================================================================
 RCS file: /usr/home/cvs/NetBSD/src/lib/libc/gen/Makefile.inc,v
 retrieving revision 1.178
 diff -u -r1.178 Makefile.inc
 --- lib/libc/gen/Makefile.inc	26 Mar 2011 19:51:42 -0000	1.178
 +++ lib/libc/gen/Makefile.inc	16 May 2011 08:41:54 -0000
 @@ -9,7 +9,7 @@
  	confstr.c ctermid.c ctype_.c daemon.c \
  	dehumanize_number.c devname.c dirname.c disklabel.c err.c errx.c \
  	errlist.c errno.c execl.c execle.c execlp.c execv.c execvp.c \
 -	extattr.c fmtcheck.c fmtmsg.c fnmatch.c fstab.c ftok.c \
 +	extattr.c finidir.c fmtcheck.c fmtmsg.c fnmatch.c fstab.c ftok.c \
  	fts.c ftw.c getbsize.c getcap.c getcwd.c \
  	getdevmajor.c getdomainname.c getgrent.c \
  	getgrouplist.c getgroupmembership.c gethostname.c \
 Index: lib/libc/gen/dirent_private.h
 ===================================================================
 RCS file: /usr/home/cvs/NetBSD/src/lib/libc/gen/dirent_private.h,v
 retrieving revision 1.4
 diff -u -r1.4 dirent_private.h
 --- lib/libc/gen/dirent_private.h	26 Sep 2010 02:26:59 -0000	1.4
 +++ lib/libc/gen/dirent_private.h	16 May 2011 09:25:47 -0000
 @@ -15,10 +15,10 @@
  struct _dirdesc;
  void _seekdir_unlocked(struct _dirdesc *, long);
  long _telldir_unlocked(struct _dirdesc *);
 -int _initdir(DIR *, int, const char *);
  void _finidir(DIR *);
  #ifndef __LIBC12_SOURCE__
  struct dirent;
 +int _initdir(DIR *, int, const char *) __RENAME(___initdir60);
  struct dirent *_readdir_unlocked(struct _dirdesc *, int)
      __RENAME(___readdir_unlocked50);
  #endif
 Index: lib/libc/gen/finidir.c
 ===================================================================
 RCS file: lib/libc/gen/finidir.c
 diff -N lib/libc/gen/finidir.c
 --- /dev/null	1 Jan 1970 00:00:00 -0000
 +++ lib/libc/gen/finidir.c	16 May 2011 09:03:10 -0000
 @@ -0,0 +1,63 @@
 +/*	$NetBSD: initdir.c,v 1.1 2010/09/26 02:26:59 yamt Exp $	*/
 +
 +/*
 + * Copyright (c) 1983, 1993
 + *	The Regents of the University of California.  All rights reserved.
 + *
 + * Redistribution and use in source and binary forms, with or without
 + * modification, are permitted provided that the following conditions
 + * are met:
 + * 1. Redistributions of source code must retain the above copyright
 + *    notice, this list of conditions and the following disclaimer.
 + * 2. Redistributions in binary form must reproduce the above copyright
 + *    notice, this list of conditions and the following disclaimer in the
 + *    documentation and/or other materials provided with the distribution.
 + * 3. Neither the name of the University nor the names of its contributors
 + *    may be used to endorse or promote products derived from this software
 + *    without specific prior written permission.
 + *
 + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 + * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 + * SUCH DAMAGE.
 + */
 +
 +#include <sys/cdefs.h>
 +#if defined(LIBC_SCCS) && !defined(lint)
 +__RCSID("$NetBSD: initdir.c,v 1.1 2010/09/26 02:26:59 yamt Exp $");
 +#endif /* LIBC_SCCS and not lint */
 +
 +#include "namespace.h"
 +#include "reentrant.h"
 +#include "extern.h"
 +
 +#include <sys/param.h>
 +
 +#include <assert.h>
 +#include <dirent.h>
 +#include <stdlib.h>
 +
 +#include "dirent_private.h"
 +
 +void
 +_finidir(DIR *dirp)
 +{
 +	struct dirpos *poslist;
 +
 +	free(dirp->dd_buf);
 +
 +	/* free seekdir/telldir storage */
 +	for (poslist = dirp->dd_internal; poslist; ) {
 +		struct dirpos *nextpos = poslist->dp_next;
 +		free(poslist);
 +		poslist = nextpos;
 +	}
 +	dirp->dd_internal = NULL;
 +}
 Index: lib/libc/gen/initdir.c
 ===================================================================
 RCS file: /usr/home/cvs/NetBSD/src/lib/libc/gen/initdir.c,v
 retrieving revision 1.1
 diff -u -r1.1 initdir.c
 --- lib/libc/gen/initdir.c	26 Sep 2010 02:26:59 -0000	1.1
 +++ lib/libc/gen/initdir.c	16 May 2011 08:40:33 -0000
 @@ -256,19 +256,3 @@
  	(void)_telldir_unlocked(dirp);
  	return 0;
  }
 -
 -void
 -_finidir(DIR *dirp)
 -{
 -	struct dirpos *poslist;
 -
 -	free(dirp->dd_buf);
 -
 -	/* free seekdir/telldir storage */
 -	for (poslist = dirp->dd_internal; poslist; ) {
 -		struct dirpos *nextpos = poslist->dp_next;
 -		free(poslist);
 -		poslist = nextpos;
 -	}
 -	dirp->dd_internal = NULL;
 -}

From: yamt@mwd.biglobe.ne.jp (YAMAMOTO Takashi)
To: tshiozak@bsdclub.org, gnats-bugs@NetBSD.org
Cc: lib-bug-people@netbsd.org, gnats-admin@netbsd.org, netbsd-bugs@netbsd.org,
	yamt@NetBSD.org
Subject: Re: PR/42879 CVS commit: src
Date: Tue,  8 May 2012 16:25:04 +0000 (UTC)

 hi,

 >  > the problem is that, the compat version of opendir is calling the newer
 >  > getdents via _initdir, right?
 >  
 >  Yes.
 >  
 >  
 >  > does rewinddir have the same problem as well?
 >  
 >  Certainly.  I didn't notice it.

 unfortunately it's too late to version rewinddir.

 how about:

 	1. version _initdir as your patch.
 	2. DIR: add a new member, dd_initdir.
 	3. opendir: dirp->dd_initdir = _initdir
 	4. rewinddir: use dirp->dd_initdir instead of _initdir.

 YAMAMOTO Takashi

From: yamt@mwd.biglobe.ne.jp (YAMAMOTO Takashi)
To: tshiozak@bsdclub.org, gnats-bugs@NetBSD.org
Cc: lib-bug-people@netbsd.org, gnats-admin@netbsd.org, netbsd-bugs@netbsd.org,
	yamt@NetBSD.org
Subject: Re: PR/42879 CVS commit: src
Date: Mon, 30 Jul 2012 02:27:06 +0000 (UTC)

 shiozaki-san, can you provide a recipe to reproduce the problem? 

 YAMAMOTO Takashi

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.