find: ignore more vanished entries with -ignore_readdir_race

Reproducer:
  # Spin up lots of short-living processes.
  $ while env true; do sleep .001; done &

  # Invoke 'find' on the /proc file system;
  # this pretty reliably gives the following error:
  $ find /proc -ignore_readdir_race -maxdepth 3 > /dev/null
  find: '/proc/845078': No such file or directory

* find/ftsfind.c (consider_visiting): Return when FTS returned ENOENT
with the option -ignore_readdir_race.
* NEWS (Bug Fixes): Mention the fix.

Fixes https://savannah.gnu.org/bugs/?45930
This commit is contained in:
2024-09-16 23:43:00 +02:00
parent 07bd7fa675
commit 889d001ab7
2 changed files with 9 additions and 0 deletions

5
NEWS
View File

@@ -2,6 +2,11 @@ GNU findutils NEWS - User visible changes. -*- outline -*- (allout)
* Noteworthy changes in release ?.? (????-??-??) [?]
** Bug Fixes
'find -ignore_readdir_race' now has a race between FTS read and the visiting
of the entry when the file was removed. [#45930]
** Documentation Changes
The forthcoming Issue 8 of the POSIX standard will standardise "find

View File

@@ -355,6 +355,10 @@ consider_visiting (FTS *p, FTSENT *ent)
}
else
{
/* Ignore unlink() error for vanished files. */
if (ENOENT == ent->fts_errno && options.ignore_readdir_race)
return;
nonfatal_target_file_error (ent->fts_errno, ent->fts_path);
/* Continue despite the error, as file name without stat info
* might be better than not even processing the file name. This