aboutsummaryrefslogtreecommitdiff
path: root/bin
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 /bin
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 'bin')
-rw-r--r--bin/chflags/chflags.c2
-rw-r--r--bin/chmod/chmod.c2
-rw-r--r--bin/cp/cp.c3
-rw-r--r--bin/ls/ls.c2
-rw-r--r--bin/rm/rm.c2
-rw-r--r--bin/setfacl/setfacl.c4
6 files changed, 9 insertions, 6 deletions
diff --git a/bin/chflags/chflags.c b/bin/chflags/chflags.c
index c1d9c18b9b6b..55dedfce53f1 100644
--- a/bin/chflags/chflags.c
+++ b/bin/chflags/chflags.c
@@ -163,7 +163,7 @@ main(int argc, char *argv[])
if ((ftsp = fts_open(++argv, fts_options , 0)) == NULL)
err(1, NULL);
- for (rval = 0; (p = fts_read(ftsp)) != NULL;) {
+ for (rval = 0; errno = 0, (p = fts_read(ftsp)) != NULL;) {
int atflag;
if ((fts_options & FTS_LOGICAL) ||
diff --git a/bin/chmod/chmod.c b/bin/chmod/chmod.c
index 07b7c37312d5..e8657af0d97b 100644
--- a/bin/chmod/chmod.c
+++ b/bin/chmod/chmod.c
@@ -164,7 +164,7 @@ done: argv += optind;
if ((ftsp = fts_open(++argv, fts_options, 0)) == NULL)
err(1, "fts_open");
- for (rval = 0; (p = fts_read(ftsp)) != NULL;) {
+ for (rval = 0; errno = 0, (p = fts_read(ftsp)) != NULL;) {
int atflag;
if ((fts_options & FTS_LOGICAL) ||
diff --git a/bin/cp/cp.c b/bin/cp/cp.c
index 6c9a57d30d78..3a23394df35d 100644
--- a/bin/cp/cp.c
+++ b/bin/cp/cp.c
@@ -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:
diff --git a/bin/ls/ls.c b/bin/ls/ls.c
index 7378268867ef..b0fe8d79e3ea 100644
--- a/bin/ls/ls.c
+++ b/bin/ls/ls.c
@@ -645,7 +645,7 @@ traverse(int argc, char *argv[], int options)
ch_options = !f_recursive && !f_label &&
options & FTS_NOSTAT ? FTS_NAMEONLY : 0;
- while ((p = fts_read(ftsp)) != NULL)
+ while (errno = 0, (p = fts_read(ftsp)) != NULL)
switch (p->fts_info) {
case FTS_DC:
warnx("%s: directory causes a cycle", p->fts_name);
diff --git a/bin/rm/rm.c b/bin/rm/rm.c
index 30eb3501eb2c..111f4a1326c4 100644
--- a/bin/rm/rm.c
+++ b/bin/rm/rm.c
@@ -207,7 +207,7 @@ rm_tree(char **argv)
return;
err(1, "fts_open");
}
- while ((p = fts_read(fts)) != NULL) {
+ while (errno = 0, (p = fts_read(fts)) != NULL) {
switch (p->fts_info) {
case FTS_DNR:
if (!fflag || p->fts_errno != ENOENT) {
diff --git a/bin/setfacl/setfacl.c b/bin/setfacl/setfacl.c
index 7b0d617812dc..033f9d2572ca 100644
--- a/bin/setfacl/setfacl.c
+++ b/bin/setfacl/setfacl.c
@@ -498,8 +498,10 @@ main(int argc, char *argv[])
/* Open all files. */
if ((ftsp = fts_open(files_list, fts_options | FTS_NOSTAT, 0)) == NULL)
err(1, "fts_open");
- while ((file = fts_read(ftsp)) != NULL)
+ while (errno = 0, (file = fts_read(ftsp)) != NULL)
carried_error += handle_file(ftsp, file);
+ if (errno != 0)
+ err(1, "fts_read");
return (carried_error);
}