Exit if working directory is not accessible: a find(1) bug or feature?

Xin LI delphij at freebsd.org
Sun Feb 5 01:43:59 PST 2006


Dear folks,

I have recently found a find(1) feature (or bug) that, it would
exit immediately if the working directory is not accessible.

HOW TO REPEAT:

[su to root]
cd /tmp
mkdir find_testcase
chmod 700 find_testcase
cd find_testcase
[su to your user, e.g. su delphij]

Now that we have an non-accessible working directory
(/tmp/find_testcase).

Any attempt of find would fail with:

	find: .: Permission Denied

This was caused by line 157-158 of find/main.c, which was
inherted from 4.4BSD.  This behavior also exists in
CentOS 3.5, OpenBSD 3.8 and Solaris 8.

It seems that the purpose of the code was to conform the
POSIX statement that:

"-exec
...
The current directory for the invocation of utility_name
shall be the same as the current directory when the find
utility was started.
..."

However, it looks somewhat confusing that find(1) refuse
to work even if no -exec is specified.

So, should we consider this as a feature (add some comments
in the BUGS section), or it's a bug that should be fixed?

Cheers,
-------------- next part --------------
Index: find.1
===================================================================
RCS file: /home/ncvs/src/usr.bin/find/find.1,v
retrieving revision 1.73
diff -u -r1.73 find.1
--- find.1	14 Jun 2005 11:50:51 -0000	1.73
+++ find.1	5 Feb 2006 09:27:17 -0000
@@ -934,3 +934,6 @@
 primaries are actually global options (as documented above).
 They should
 probably be replaced by options which look like options.
+.Pp
+.Nm
+will exit immediately if the working directory is not accessible.


More information about the freebsd-standards mailing list