summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Burridge <rich.burridge@oracle.com>2010-06-07 13:43:38 -0700
committerRich Burridge <rich.burridge@oracle.com>2010-06-07 13:43:38 -0700
commit4b808d4335c4994a826d481c0af6c0ccaafbeff8 (patch)
treeefab9e135ba3453db740897e2405f6c713dd412f
parentf6da83d4178694e7113b71d1e452f15b296f73d8 (diff)
downloadillumos-gate-4b808d4335c4994a826d481c0af6c0ccaafbeff8.tar.gz
6470471 find should work even if a parent directory is read-protected
-rw-r--r--usr/src/cmd/find/find.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/usr/src/cmd/find/find.c b/usr/src/cmd/find/find.c
index bd5df9734c..8934b41988 100644
--- a/usr/src/cmd/find/find.c
+++ b/usr/src/cmd/find/find.c
@@ -341,10 +341,20 @@ main(int argc, char **argv)
* error related to this
*/
if ((cwdpath = getcwd(NULL, PATH_MAX)) == NULL) {
- (void) fprintf(stderr,
- gettext("%s : cannot get the current working "
- "directory\n"), cmdname);
- exit(1);
+ if ((errno == EACCES) && (walkflags & FTW_CHDIR)) {
+ /*
+ * A directory above cwd is inaccessible,
+ * so don't do chdir(2)s. Slower, but at least
+ * it works.
+ */
+ walkflags &= ~FTW_CHDIR;
+ free(cwdpath);
+ } else {
+ (void) fprintf(stderr,
+ gettext("%s : cannot get the current "
+ "working directory\n"), cmdname);
+ exit(1);
+ }
} else
free(cwdpath);