I wrote a test program that mixed calls of opendir() and fdopendir()
with rewinddir() and counted the number of entries found by readdir()
at each stage. For the fdopendir() the simple case was to open a
directory, use SEEK_END to seek to the end, then fdopendir/rewinddir.
The readdir() loop then found zero entries without the fix. For the
unionfs fixes, I setup a unionfs in a VM and ran the program under gdb
so that I could alter the state of the lower filesystem (add a new file
or remove a file) after a readdir() loop but before rewinddir() and
verify the program observed the updated count after the rewind.
Two further considerations:
1) rewinddir() could probably call _reclaim_telldir() as POSIX says that
positions returned from telldir() are invalidatd by a rewinddir().
2) If fdopendir() is passed a non-directory and fails, the file is currently
still marked as close-on-exec.