aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorBryan Drewery <bdrewery@FreeBSD.org>2020-12-08 23:38:26 +0000
committerBryan Drewery <bdrewery@FreeBSD.org>2020-12-08 23:38:26 +0000
commit2dfa4b66b3d0caaaae6ce2df476b5615f8415a19 (patch)
tree550fa72fe4f1d83dfdc72e6db29170e0e6940f77 /contrib
parentf1b18a668deb2aab9e2da908a403d58bce029d80 (diff)
downloadsrc-2dfa4b66b3d0caaaae6ce2df476b5615f8415a19.tar.gz
src-2dfa4b66b3d0caaaae6ce2df476b5615f8415a19.zip
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
Notes
Notes: svn path=/head/; revision=368467
Diffstat (limited to 'contrib')
-rw-r--r--contrib/mtree/create.c4
-rw-r--r--contrib/mtree/verify.c4
2 files changed, 6 insertions, 2 deletions
diff --git a/contrib/mtree/create.c b/contrib/mtree/create.c
index dc3af7447a39..7a09a1cc3951 100644
--- a/contrib/mtree/create.c
+++ b/contrib/mtree/create.c
@@ -129,7 +129,7 @@ cwalk(FILE *fp)
if ((t = fts_open(argv, ftsoptions, dcmp)) == NULL)
mtree_err("fts_open: %s", strerror(errno));
- while ((p = fts_read(t)) != NULL) {
+ while (errno = 0, (p = fts_read(t)) != NULL) {
if (jflag)
indent = p->fts_level * 4;
if (check_excludes(p->fts_name, p->fts_path)) {
@@ -173,6 +173,8 @@ cwalk(FILE *fp)
}
}
+ if (errno != 0)
+ mtree_err("fts_read: %s", strerror(errno));
fts_close(t);
if (sflag && keys & F_CKSUM)
mtree_err("%s checksum: %u", fullpath, crc_total);
diff --git a/contrib/mtree/verify.c b/contrib/mtree/verify.c
index 66b020ac8b9f..4aca42c52aea 100644
--- a/contrib/mtree/verify.c
+++ b/contrib/mtree/verify.c
@@ -90,7 +90,7 @@ vwalk(void)
mtree_err("fts_open: %s", strerror(errno));
level = root;
specdepth = rval = 0;
- while ((p = fts_read(t)) != NULL) {
+ while (errno = 0, (p = fts_read(t)) != NULL) {
if (check_excludes(p->fts_name, p->fts_path)) {
fts_set(t, p, FTS_SKIP);
continue;
@@ -160,6 +160,8 @@ vwalk(void)
}
fts_set(t, p, FTS_SKIP);
}
+ if (errno != 0)
+ mtree_err("fts_read: %s", strerror(errno));
fts_close(t);
if (sflag)
warnx("%s checksum: %u", fullpath, crc_total);