fts_read: Handle error from a NULL return better.

This is addressing cases such as fts_read(3) encountering an [EIO]
from fchdir(2) when FTS_NOCHDIR is not set.  That would otherwise be
seen as a successful traversal in some of these cases while silently
discarding expected work.

As noted in r264201, fts_read() does not set errno to 0 on a successful
EOF so it needs to be set before calling it.  Otherwise we might see
a random error from one of the iterations.

gzip is ignoring most errors and could be improved separately.

Reviewed by:	vangyzen
Sponsored by:	Dell EMC
Differential Revision:	https://reviews.freebsd.org/D27184
This commit is contained in:
Bryan Drewery
2020-12-08 23:38:26 +00:00
parent f1b18a668d
commit 2dfa4b66b3
16 changed files with 33 additions and 16 deletions
+2 -1
View File
@@ -282,7 +282,8 @@ copy(char *argv[], enum op type, int fts_options)
if ((ftsp = fts_open(argv, fts_options, NULL)) == NULL)
err(1, "fts_open");
for (badcp = rval = 0; (curr = fts_read(ftsp)) != NULL; badcp = 0) {
for (badcp = rval = 0; errno = 0, (curr = fts_read(ftsp)) != NULL;
badcp = 0) {
switch (curr->fts_info) {
case FTS_NS:
case FTS_DNR: