From nobody@FreeBSD.org  Wed Mar 14 15:14:52 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 1A6211065672
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 14 Mar 2012 15:14:52 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id DFEA28FC0A
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 14 Mar 2012 15:14:51 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id q2EFEp9w084674
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 14 Mar 2012 15:14:51 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id q2EFEpjG084673;
	Wed, 14 Mar 2012 15:14:51 GMT
	(envelope-from nobody)
Message-Id: <201203141514.q2EFEpjG084673@red.freebsd.org>
Date: Wed, 14 Mar 2012 15:14:51 GMT
From: Matthew Story <matthewstory@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [docs][libc] fts(3) should document cases where FTS_NOCHDIR option is set as a side-effect
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         166091
>Category:       docs
>Synopsis:       [libc][patch] fts(3) should document cases where FTS_NOCHDIR option is set as a side-effect
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    jilles
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          doc-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Mar 14 15:20:01 UTC 2012
>Closed-Date:    Sun Mar 25 20:27:43 UTC 2012
>Last-Modified:  Sun Mar 25 20:27:43 UTC 2012
>Originator:     Matthew Story
>Release:        8.2
>Organization:
>Environment:
FreeBSD axe0.blackskyresearch.net 8.2-RELEASE-p2 FreeBSD 8.2-RELEASE-p2 #0: Sun Jul  3 00:57:18 EDT 2011     root@osprey.blackskyresearch.net:/usr/obj/usr/src/sys/blackskyresearch-amd64-8-2-20110702  amd64
>Description:
fts(3) sets the FTS_NOCHDIR flag in 2 cases aside from when it is explicitly provided to fts_open(3)

1. FTS_LOGICAL flag is provided to fts_open(3)

 145     /* Logical walks turn on NOCHDIR; symbolic links are too hard. */
 146     if (ISSET(FTS_LOGICAL))
 147         SET(FTS_NOCHDIR);

2. fts_open(3) cannot open(2) `.'

 209     /*
 210      * If using chdir(2), grab a file descriptor pointing to dot to ensure
 211      * that we can get back here; this could be avoided for some paths,
 212      * but almost certainly not worth the effort.  Slashes, symbolic links,
 213      * and ".." are all fairly nasty problems.  Note, if we can't get the
 214      * descriptor we run anyway, just more slowly.
 215      */
 216     if (!ISSET(FTS_NOCHDIR) && (sp->fts_rfd = _open(".", O_RDONLY, 0)) < 0)
 217         SET(FTS_NOCHDIR);

A misunderstanding of the former case caused find(1) to not traverse directories properly for -execdir when the -L option was specified (see bin/166056)
>How-To-Repeat:
man 3 fts
>Fix:
apply patch (patch is against head), patch is available via http here:

http://axe0.blackskyresearch.net/patches/matt/fts.3.add_FTS_NOCHDIR_side_effect_cases.patch.txt

Patch attached with submission follows:

Index: fts.3
===================================================================
--- fts.3	(revision 232972)
+++ fts.3	(working copy)
@@ -410,6 +410,12 @@
 .Vt FTSENT
 structures
 are returned to the application are those referencing non-existent files.
+Providing the 
+.Dv FTS_LOGICAL
+option to the
+.Fn fts_open
+function will set 
+.Dv FTS_NOCHDIR .
 Either
 .Dv FTS_LOGICAL
 or
@@ -435,6 +441,17 @@
 is specified and absolute
 pathnames were provided as arguments to
 .Fn fts_open .
+The
+.Dv FTS_NOCHDIR 
+option will be set if the
+.Dv FTS_LOGICAL 
+option is provided to the
+.Fn fts_open
+function, or if 
+.Fn fts_open
+cannot
+.Xr open 2
+.Ql .\& .
 .It Dv FTS_NOSTAT
 By default, returned
 .Vt FTSENT


>Release-Note:
>Audit-Trail:

From: Jilles Tjoelker <jilles@stack.nl>
To: bug-followup@FreeBSD.org, matthewstory@gmail.com
Cc:  
Subject: Re: docs/166091: [libc][patch] fts(3) should document cases where
 FTS_NOCHDIR option is set as a side-effect
Date: Fri, 16 Mar 2012 23:38:53 +0100

 > [fts(3) automatically sets FTS_NOCHDIR option in some cases]
 
 I consider the automatic FTS_NOCHDIR a semi-bug that should not be
 relied on. If FTS_NOCHDIR is set, fts(3) runs slower and is subject to
 {PATH_MAX}. The latter would violate POSIX in various utilities.
 
 I tried to allow FTS_LOGICAL without FTS_NOCHDIR a while ago, but while
 it is conceptually possible, actually making it work is hard.
 
 The open(".", O_RDONLY) can use O_SEARCH when it is added (for now,
 O_EXEC works) so it only needs 'x' right not also 'r'.
 
 -- 
 Jilles Tjoelker

From: Matthew Story <matthewstory@gmail.com>
To: Jilles Tjoelker <jilles@stack.nl>
Cc: bug-followup@freebsd.org
Subject: Re: docs/166091: [libc][patch] fts(3) should document cases where
 FTS_NOCHDIR option is set as a side-effect
Date: Fri, 16 Mar 2012 19:02:47 -0400

 --20cf3071cf260a2e7f04bb64357f
 Content-Type: text/plain; charset=ISO-8859-1
 
 On Fri, Mar 16, 2012 at 6:38 PM, Jilles Tjoelker <jilles@stack.nl> wrote:
 
 > > [fts(3) automatically sets FTS_NOCHDIR option in some cases]
 >
 > I consider the automatic FTS_NOCHDIR a semi-bug that should not be
 > relied on.
 
 
 I agree with this, but as the behavior is non-obvious I think it should be
 noted.  Perhaps this is more appropriate for the BUGS section than the
 fts_open section?
 
 
 > If FTS_NOCHDIR is set, fts(3) runs slower and is subject to
 > {PATH_MAX}. The latter would violate POSIX in various utilities.
 >
 
 this would mean that find -L is currently in violation of POSIX?
 
 I tried to allow FTS_LOGICAL without FTS_NOCHDIR a while ago, but while
 > it is conceptually possible, actually making it work is hard.
 >
 
 Is anyone currently looking into this?
 
 
 >
 > The open(".", O_RDONLY) can use O_SEARCH when it is added (for now,
 > O_EXEC works) so it only needs 'x' right not also 'r'.
 >
 
 So this would then fall back to FTS_NOCHDIR if `.' is not searchable?
 
 
 >
 > --
 > Jilles Tjoelker
 >
 
 
 
 -- 
 regards,
 matt
 
 --20cf3071cf260a2e7f04bb64357f--

From: Jilles Tjoelker <jilles@stack.nl>
To: Matthew Story <matthewstory@gmail.com>
Cc: bug-followup@freebsd.org
Subject: Re: docs/166091: [libc][patch] fts(3) should document cases where
 FTS_NOCHDIR option is set as a side-effect
Date: Sat, 17 Mar 2012 16:11:03 +0100

 On Fri, Mar 16, 2012 at 07:02:47PM -0400, Matthew Story wrote:
 > On Fri, Mar 16, 2012 at 6:38 PM, Jilles Tjoelker <jilles@stack.nl> wrote:
 
 > > > [fts(3) automatically sets FTS_NOCHDIR option in some cases]
 
 > > I consider the automatic FTS_NOCHDIR a semi-bug that should not be
 > > relied on.
 
 > I agree with this, but as the behavior is non-obvious I think it should be
 > noted.  Perhaps this is more appropriate for the BUGS section than the
 > fts_open section?
 
 Yes.
 
 > > If FTS_NOCHDIR is set, fts(3) runs slower and is subject to
 > > {PATH_MAX}. The latter would violate POSIX in various utilities.
 
 > this would mean that find -L is currently in violation of POSIX?
 
 Yes. The POSIX page about find is pretty clear on this issue:
 
 % The find utility shall be able to descend to arbitrary depths in a
 % file hierarchy and shall not fail due to path length limitations
 % (unless a path operand specified by the application exceeds {PATH_MAX}
 % requirements)
 
 > I tried to allow FTS_LOGICAL without FTS_NOCHDIR a while ago, but while
 > > it is conceptually possible, actually making it work is hard.
 
 > Is anyone currently looking into this?
 
 No. My patch (from over a year ago) is at
 http://www.stack.nl/~jilles/unix/fts-logical-chdir-2.patch but I forgot
 what severe breakage it causes.
 
 > > The open(".", O_RDONLY) can use O_SEARCH when it is added (for now,
 > > O_EXEC works) so it only needs 'x' right not also 'r'.
 
 > So this would then fall back to FTS_NOCHDIR if `.' is not searchable?
 
 Yes. This could be avoided by using functions like openat(2) and
 fstatat(2) instead of changing the current directory, but only by
 changing the API (because the current API requires fts(3) to furnish a
 pathname that will access the object, not an fd and a pathname relative
 to it).
 
 -- 
 Jilles Tjoelker

From: Matthew Story <matthewstory@gmail.com>
To: Jilles Tjoelker <jilles@stack.nl>
Cc: bug-followup@freebsd.org
Subject: Re: docs/166091: [libc][patch] fts(3) should document cases where
 FTS_NOCHDIR option is set as a side-effect
Date: Sat, 17 Mar 2012 12:07:38 -0400

 --14dae9cdc1072cb56904bb728610
 Content-Type: multipart/alternative; boundary=14dae9cdc1072cb56204bb72860e
 
 --14dae9cdc1072cb56204bb72860e
 Content-Type: text/plain; charset=ISO-8859-1
 
 Updated patch (attached) to document the side-effect cases in BUGS section,
 available via http here:
 
 http://axe0.blackskyresearch.net/patches/matt/fts.3.add_FTS_NOCHDIR_side_effect_cases.patch.txt
 
 > % file hierarchy and shall not fail due to path length limitations
 > % (unless a path operand specified by the application exceeds {PATH_MAX}
 > % requirements)
 >
 
 so find should only fail if an argument sent already exceeds PATH_MAX,
 understood.
 
 
 > > I tried to allow FTS_LOGICAL without FTS_NOCHDIR a while ago, but while
 > > > it is conceptually possible, actually making it work is hard.
 >
 > > Is anyone currently looking into this?
 >
 > No. My patch (from over a year ago) is at
 > http://www.stack.nl/~jilles/unix/fts-logical-chdir-2.patch but I forgot
 > what severe breakage it causes.
 >
 > > > The open(".", O_RDONLY) can use O_SEARCH when it is added (for now,
 > > > O_EXEC works) so it only needs 'x' right not also 'r'.
 >
 > > So this would then fall back to FTS_NOCHDIR if `.' is not searchable?
 >
 > Yes. This could be avoided by using functions like openat(2) and
 > fstatat(2) instead of changing the current directory, but only by
 > changing the API (because the current API requires fts(3) to furnish a
 > pathname that will access the object, not an fd and a pathname relative
 > to it).
 >
 
 couldn't this be accommodated by internally maintaining an fd to each path?
  Alternatively, adding an fts_openat function would allow for this
 behavior, without modifying the imprint of fts_open.
 
 
 >
 > --
 > Jilles Tjoelker
 
 
 
 
 -- 
 regards,
 matt
 
 --14dae9cdc1072cb56204bb72860e--
 --14dae9cdc1072cb56904bb728610
 Content-Type: text/plain; charset=US-ASCII; 
 	name="fts.3.add_FTS_NOCHDIR_side_effect_cases.patch.txt"
 Content-Disposition: attachment; 
 	filename="fts.3.add_FTS_NOCHDIR_side_effect_cases.patch.txt"
 Content-Transfer-Encoding: base64
 X-Attachment-Id: f_gzwujk9t0
 
 SW5kZXg6IGZ0cy4zCj09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
 PT09PT09PT09PT09PT09PT09PT09PT0KLS0tIGZ0cy4zCShyZXZpc2lvbiAyMzMwODkpCisrKyBm
 dHMuMwkod29ya2luZyBjb3B5KQpAQCAtNzk4LDMgKzc5OCwxMyBAQAogcHJpbmNpcGFsbHkgdG8g
 cHJvdmlkZSBmb3IgYWx0ZXJuYXRpdmUgaW50ZXJmYWNlcyB0byB0aGUKIC5ObQogZnVuY3Rpb25h
 bGl0eSB1c2luZyBkaWZmZXJlbnQgZGF0YSBzdHJ1Y3R1cmVzLgorLlNoIEJVR1MKK1RoZSAKKy5G
 biBmdHNfb3BlbgorZnVuY3Rpb24gd2lsbCBhdXRvbWF0aWNhbGx5IHNldCB0aGUKKy5EdiBGVFNf
 Tk9DSERJUgorb3B0aW9uIGlmIHRoZSAKKy5EdiBGVFNfTE9HSUNBTAorb3B0aW9uIGlzIHByb3Zp
 ZGVkLCBvciBpZiBpdCBjYW5ub3QgCisuWHIgb3BlbiAyCisuUWwgLlwmIC4K
 --14dae9cdc1072cb56904bb728610--

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: docs/166091: commit references a PR
Date: Sun, 18 Mar 2012 20:34:11 +0000 (UTC)

 Author: jilles
 Date: Sun Mar 18 20:34:01 2012
 New Revision: 233130
 URL: http://svn.freebsd.org/changeset/base/233130
 
 Log:
   fts(3): Document cases where FTS_NOCHDIR is set implicitly.
   
   PR:		docs/166091
   Submitted by:	Matthew Story
   MFC after:	1 week
 
 Modified:
   head/lib/libc/gen/fts.3
 
 Modified: head/lib/libc/gen/fts.3
 ==============================================================================
 --- head/lib/libc/gen/fts.3	Sun Mar 18 19:35:30 2012	(r233129)
 +++ head/lib/libc/gen/fts.3	Sun Mar 18 20:34:01 2012	(r233130)
 @@ -28,7 +28,7 @@
  .\"     @(#)fts.3	8.5 (Berkeley) 4/16/94
  .\" $FreeBSD$
  .\"
 -.Dd November 25, 2009
 +.Dd March 18, 2012
  .Dt FTS 3
  .Os
  .Sh NAME
 @@ -798,3 +798,13 @@ functions were introduced in
  principally to provide for alternative interfaces to the
  .Nm
  functionality using different data structures.
 +.Sh BUGS
 +The 
 +.Fn fts_open
 +function will automatically set the
 +.Dv FTS_NOCHDIR
 +option if the 
 +.Dv FTS_LOGICAL
 +option is provided, or if it cannot 
 +.Xr open 2
 +the current directory.
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: jilles 
State-Changed-When: Sun Mar 18 20:46:25 UTC 2012 
State-Changed-Why:  
Fixed in head. 


Responsible-Changed-From-To: freebsd-doc->jilles 
Responsible-Changed-By: jilles 
Responsible-Changed-When: Sun Mar 18 20:46:25 UTC 2012 
Responsible-Changed-Why:  
Take. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=166091 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: docs/166091: commit references a PR
Date: Sun, 25 Mar 2012 20:01:12 +0000 (UTC)

 Author: jilles
 Date: Sun Mar 25 20:01:03 2012
 New Revision: 233474
 URL: http://svn.freebsd.org/changeset/base/233474
 
 Log:
   MFC r233130: fts(3): Document cases where FTS_NOCHDIR is set implicitly.
   
   PR:		docs/166091
   Submitted by:	Matthew Story
 
 Modified:
   stable/9/lib/libc/gen/fts.3
 Directory Properties:
   stable/9/lib/libc/   (props changed)
 
 Modified: stable/9/lib/libc/gen/fts.3
 ==============================================================================
 --- stable/9/lib/libc/gen/fts.3	Sun Mar 25 19:34:05 2012	(r233473)
 +++ stable/9/lib/libc/gen/fts.3	Sun Mar 25 20:01:03 2012	(r233474)
 @@ -28,7 +28,7 @@
  .\"     @(#)fts.3	8.5 (Berkeley) 4/16/94
  .\" $FreeBSD$
  .\"
 -.Dd November 25, 2009
 +.Dd March 18, 2012
  .Dt FTS 3
  .Os
  .Sh NAME
 @@ -798,3 +798,13 @@ functions were introduced in
  principally to provide for alternative interfaces to the
  .Nm
  functionality using different data structures.
 +.Sh BUGS
 +The 
 +.Fn fts_open
 +function will automatically set the
 +.Dv FTS_NOCHDIR
 +option if the 
 +.Dv FTS_LOGICAL
 +option is provided, or if it cannot 
 +.Xr open 2
 +the current directory.
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: docs/166091: commit references a PR
Date: Sun, 25 Mar 2012 20:08:03 +0000 (UTC)

 Author: jilles
 Date: Sun Mar 25 20:07:50 2012
 New Revision: 233476
 URL: http://svn.freebsd.org/changeset/base/233476
 
 Log:
   MFC r233130: fts(3): Document cases where FTS_NOCHDIR is set implicitly.
   
   PR:		docs/166091
   Submitted by:	Matthew Story
 
 Modified:
   stable/8/lib/libc/gen/fts.3
 Directory Properties:
   stable/8/lib/libc/   (props changed)
 
 Modified: stable/8/lib/libc/gen/fts.3
 ==============================================================================
 --- stable/8/lib/libc/gen/fts.3	Sun Mar 25 20:03:13 2012	(r233475)
 +++ stable/8/lib/libc/gen/fts.3	Sun Mar 25 20:07:50 2012	(r233476)
 @@ -28,7 +28,7 @@
  .\"     @(#)fts.3	8.5 (Berkeley) 4/16/94
  .\" $FreeBSD$
  .\"
 -.Dd November 25, 2009
 +.Dd March 18, 2012
  .Dt FTS 3
  .Os
  .Sh NAME
 @@ -798,3 +798,13 @@ functions were introduced in
  principally to provide for alternative interfaces to the
  .Nm
  functionality using different data structures.
 +.Sh BUGS
 +The 
 +.Fn fts_open
 +function will automatically set the
 +.Dv FTS_NOCHDIR
 +option if the 
 +.Dv FTS_LOGICAL
 +option is provided, or if it cannot 
 +.Xr open 2
 +the current directory.
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: jilles 
State-Changed-When: Sun Mar 25 20:27:15 UTC 2012 
State-Changed-Why:  
Fixed in head, stable/9 and stable/8. 

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