diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2009-12-09 13:59:44 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2009-12-09 13:59:44 +0000 |
commit | f699d60fad50f050a8c1c226bd1e9da0b20f59fb (patch) | |
tree | bdf5b9815b92fd18dde6916127a53b24ac32e484 | |
parent | 4de50585e6004591ea1bd4250e88cea32a08ae70 (diff) |
We only need to fchdir(dotfd) for the -exec and -ok primaries so
defer the check for dotfd != -1 until we know we will need it.
Based on a diff from schwarze@
-rw-r--r-- | usr.bin/find/function.c | 6 | ||||
-rw-r--r-- | usr.bin/find/main.c | 7 |
2 files changed, 8 insertions, 5 deletions
diff --git a/usr.bin/find/function.c b/usr.bin/find/function.c index 89b0db7cc19..662d4921ccc 100644 --- a/usr.bin/find/function.c +++ b/usr.bin/find/function.c @@ -1,4 +1,4 @@ -/* $OpenBSD: function.c,v 1.34 2009/10/27 23:59:38 deraadt Exp $ */ +/* $OpenBSD: function.c,v 1.35 2009/12/09 13:59:43 millert Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -399,6 +399,10 @@ c_exec(char *unused, char ***argvp, int isok) int cnt; char **argv, **ap, *p; + /* make sure the current directory is readable */ + if (dotfd == -1) + errx(1, "%s: cannot open \".\"", isok ? "-ok" : "-exec"); + isoutput = 1; new = palloc(N_EXEC, f_exec); diff --git a/usr.bin/find/main.c b/usr.bin/find/main.c index 8c2190b98d1..48b2123c290 100644 --- a/usr.bin/find/main.c +++ b/usr.bin/find/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.24 2009/10/27 23:59:38 deraadt Exp $ */ +/* $OpenBSD: main.c,v 1.25 2009/12/09 13:59:43 millert Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -45,7 +45,7 @@ #include "find.h" time_t now; /* time find was run */ -int dotfd; /* starting directory */ +int dotfd; /* starting directory; may be -1 */ int ftsoptions; /* options for the fts_open(3) call */ int isdepth; /* do directories on post-order visit */ int isoutput; /* user specified output operator */ @@ -121,8 +121,7 @@ main(int argc, char *argv[]) err(1, NULL); paths = paths2; - if ((dotfd = open(".", O_RDONLY, 0)) < 0) - err(1, ".:"); + dotfd = open(".", O_RDONLY, 0); find_execute(find_formplan(argv), paths); exit(0); |