aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/find/find.c
diff options
context:
space:
mode:
authorJilles Tjoelker <jilles@FreeBSD.org>2014-04-12 22:36:26 +0000
committerJilles Tjoelker <jilles@FreeBSD.org>2014-04-12 22:36:26 +0000
commit7a79617cc15ccab1d91b9e27b01d54104f71f4e7 (patch)
treeb025d3252093a31ed23ae4720ab00cb625bfa5dc /usr.bin/find/find.c
parent1efb0053e4837383f8ac05cc1e2d1727acde5bec (diff)
downloadsrc-7a79617cc15ccab1d91b9e27b01d54104f71f4e7.tar.gz
src-7a79617cc15ccab1d91b9e27b01d54104f71f4e7.zip
find: Correctly propagate -exec/-execdir ... {} + exit status.
As per POSIX, the -exec ... {} + primary always returns true, but a non-zero exit status causes find to return a non-zero exit status itself. GNU does the same, and also for -execdir ... {} +. It does not make much sense to return false from the primary only when the child process happens to be run. The behaviour for -exec/-execdir ... ; remains unchanged: the primary returns true or false depending on the exit status, and find's exit status is unaffected.
Notes
Notes: svn path=/head/; revision=264387
Diffstat (limited to 'usr.bin/find/find.c')
-rw-r--r--usr.bin/find/find.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/usr.bin/find/find.c b/usr.bin/find/find.c
index e59773f49d93..3e5d56b0217b 100644
--- a/usr.bin/find/find.c
+++ b/usr.bin/find/find.c
@@ -175,13 +175,14 @@ find_execute(PLAN *plan, char *paths[])
{
FTSENT *entry;
PLAN *p;
- int e, rval;
+ int e;
tree = fts_open(paths, ftsoptions, (issort ? find_compare : NULL));
if (tree == NULL)
err(1, "ftsopen");
- for (rval = 0; errno = 0, (entry = fts_read(tree)) != NULL;) {
+ exitstatus = 0;
+ while (errno = 0, (entry = fts_read(tree)) != NULL) {
if (maxdepth != -1 && entry->fts_level >= maxdepth) {
if (fts_set(tree, entry, FTS_SKIP))
err(1, "%s", entry->fts_path);
@@ -206,7 +207,7 @@ find_execute(PLAN *plan, char *paths[])
(void)fflush(stdout);
warnx("%s: %s",
entry->fts_path, strerror(entry->fts_errno));
- rval = 1;
+ exitstatus = 1;
continue;
#ifdef FTS_W
case FTS_W:
@@ -217,7 +218,7 @@ find_execute(PLAN *plan, char *paths[])
if (isxargs && strpbrk(entry->fts_path, BADCH)) {
(void)fflush(stdout);
warnx("%s: illegal path", entry->fts_path);
- rval = 1;
+ exitstatus = 1;
continue;
}
@@ -235,5 +236,5 @@ find_execute(PLAN *plan, char *paths[])
finish_execplus();
if (e && (!ignore_readdir_race || e != ENOENT))
errc(1, e, "fts_read");
- return (rval);
+ return (exitstatus);
}