diff --git a/ChangeLog b/ChangeLog index ec474c28..d2bab90d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2013-09-22 James Youngman + + Issue an error message when fts_read fails. Fixes bug #39324. + * find/ftsfind.c (find): when fts_read fails, issue an error + message, set the exit status to zero and stop. Previously the + program would just stop (i.e. it failed to distinguish "done" from + "failed"). + * find/find.1 (-exec): explain that on failure, some pending + command launches may not happen. The Texinfo documentation + already pointed this out, so that didn't need to be changed. + * NEWS: Mention this bugfix. + 2013-09-21 James Youngman find: state that -execdir command is run locally to the matched file. diff --git a/NEWS b/NEWS index 9202acc1..102086ff 100644 --- a/NEWS +++ b/NEWS @@ -47,6 +47,8 @@ database, though they are in the ChangeLog: These following fixed bugs are recorded at https://savannah.gnu.org/bugs/?group=findutils: +#39324: exits without error on OOM + #38474: Unintended (?) behaviour change of -perm +mode predicate #38583: errno-buffer read failed in xargs_do_exec diff --git a/find/find.1 b/find/find.1 index 9a23d451..b916ad01 100644 --- a/find/find.1 +++ b/find/find.1 @@ -1014,7 +1014,11 @@ command will be much less than the number of matched files. The command line is built in much the same way that .B xargs builds its command lines. Only one instance of `{}' is allowed within -the command. The command is executed in the starting directory. +the command. The command is executed in the starting directory. If +.B find +encounters an error, this can sometimes cause an +immediate exit, so some pending commands may not be run +at all. .IP "\-execdir \fIcommand\fR ;" .IP "\-execdir \fIcommand\fR {} +" @@ -1043,7 +1047,11 @@ appropriately-named file in a directory in which you will run .BR \-execdir . The same applies to having entries in .B $PATH -which are empty or which are not absolute directory names. +which are empty or which are not absolute directory names. If +.B find +encounters an error, this can sometimes cause an +immediate exit, so some pending commands may not be run +at all. .IP "\-fls \fIfile\fR" True; like @@ -2020,6 +2028,17 @@ description, but if the return value is non-zero, you should not rely on the correctness of the results of .BR find . +When some error occurs, +.B find +may stop immeidately, without completing all the actions specified. +For example, some starting points may not have been examined or some +pending program invocations for +.B \-exec ... {} + +or +.B \-execdir ... {} + +may not have been performed. + + .SH "SEE ALSO" \fBlocate\fP(1), \fBlocatedb\fP(5), \fBupdatedb\fP(1), \fBxargs\fP(1), \fBchmod\fP(1), \fBfnmatch\fP(3), \fBregex\fP(7), \fBstat\fP(2), diff --git a/find/ftsfind.c b/find/ftsfind.c index 0359134f..e97bd7d0 100644 --- a/find/ftsfind.c +++ b/find/ftsfind.c @@ -564,7 +564,7 @@ find (char *arg) { int level = INT_MIN; - while ( (ent=fts_read (p)) != NULL ) + while ( (errno=0, ent=fts_read (p)) != NULL ) { if (state.execdirs_outstanding) { @@ -589,6 +589,16 @@ find (char *arg) state.type = state.have_type ? ent->fts_statp->st_mode : 0; consider_visiting (p, ent); } + /* fts_read returned NULL; distinguish between "finished" and "error". */ + if (errno) + { + error (0, errno, + "failed to read file names from file system at or below %s", + safely_quote_err_filename (0, arg)); + error_severity (EXIT_FAILURE); + return false; + } + if (0 != fts_close (p)) { /* Here we break the abstraction of fts_close a bit, because we