diff options
author | jilles <jilles@FreeBSD.org> | 2014-04-06 20:04:33 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2014-04-06 20:04:33 +0000 |
commit | ae85877db58569f74d4dce6b686de355cf9d0e36 (patch) | |
tree | b6b1ffb38071ef38ee64f2ec1d0ca439b1182126 | |
parent | b97204b78683cec60e82d9fdf03397b233227e60 (diff) | |
download | FreeBSD-src-ae85877db58569f74d4dce6b686de355cf9d0e36.zip FreeBSD-src-ae85877db58569f74d4dce6b686de355cf9d0e36.tar.gz |
find: Treat errno from fts_read() more carefully.
fts_read() leaves errno unchanged on EOF and sets it on error, so set errno
to 0 before calling it. Also, don't trust finish_execplus() to leave errno
unchanged.
-rw-r--r-- | usr.bin/find/find.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/usr.bin/find/find.c b/usr.bin/find/find.c index 8ad76c1..e59773f 100644 --- a/usr.bin/find/find.c +++ b/usr.bin/find/find.c @@ -175,13 +175,13 @@ find_execute(PLAN *plan, char *paths[]) { FTSENT *entry; PLAN *p; - int rval; + int e, rval; tree = fts_open(paths, ftsoptions, (issort ? find_compare : NULL)); if (tree == NULL) err(1, "ftsopen"); - for (rval = 0; (entry = fts_read(tree)) != NULL;) { + for (rval = 0; 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); @@ -231,8 +231,9 @@ find_execute(PLAN *plan, char *paths[]) */ for (p = plan; p && (p->execute)(p, entry); p = p->next); } + e = errno; finish_execplus(); - if (errno && (!ignore_readdir_race || errno != ENOENT)) - err(1, "fts_read"); + if (e && (!ignore_readdir_race || e != ENOENT)) + errc(1, e, "fts_read"); return (rval); } |