Date: Mon, 01 Mar 2021 16:58:07 +0100 From: Florian Weimer <fweimer@...hat.com> To: enh <enh@...gle.com> Cc: libc-coord@...ts.openwall.com, Rich Felker <dalias@...c.org> Subject: Re: Lifetime of object returned by readdir > On Tue, Feb 23, 2021 at 10:32 AM Florian Weimer <fweimer@...hat.com> wrote: > > > POSIX already explicitly says that seekdir() affects the _next_ > > readdir(). > > That's because it's the only way its effect is observable. > > The glibc implementation of seekdir performs an immediate seek, but if > the seek fails, that error is not really observable (except for reading > the implementation and inferring that the errno = 0 hack will work). I > had not realized that seekdir returns void. Maybe that argues in favor > of a delayed seek upon the next readdir call. > > > does anyone have an implementation where rewinddir()/seekdir() > > actually invalidate the previous readdir()? seems unlikely? > > Probably not. But there's also the issue of fitting the directory > offset (usually off64_t, maybe even something larger) into the long int > return value of telldir, so there could be quite a bit of magic going on > in the background (considering that telldir cannot indicate failure). > > i suspect anyone iterating over a directory that large has other > problems :-) As has already been said, it's not necessarily a matter of directory size. > fwiw, the only calls to telldir() or seekdir() in Android (not > counting any vendor blobs i can't see the source to) are in the bionic > unit tests and other languages' runtime wrappers (rust/python). There are some thorny issues about read position invalidation and file deletion. It's strange we don't see more issues around that. I would expect that a readdir/unlink loop would fail to empty a directory in at least some cases. Maybe bulk deletion tools retry at a higher level if they encounter an rmdir ENOTEMPTY failure. Thanks, Florian
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.