Page MenuHomeFreeBSD

opendir, fdopendir: Add tests, improve robustness.
ClosedPublic

Authored by des on Wed, Jul 2, 11:51 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Jul 20, 4:40 PM
Unknown Object (File)
Tue, Jul 8, 7:57 PM
Unknown Object (File)
Mon, Jul 7, 10:06 PM
Subscribers

Details

Summary
  • Add test cases for opendir() and fdopendir().
  • Drop O_NONBLOCK from opendir(); it was added a long time ago to avoid blocking if given a closed named pipe, but now we use O_DIRECTORY, which ensures that we get ENOTDIR in that case.
  • While here, remove unused #includes left over from the split.

Sponsored by: Klara, Inc.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 65278
Build 62161: arc lint + arc unit

Event Timeline

des requested review of this revision.Wed, Jul 2, 11:51 AM

no need for <sys/param.h>

kevans added subscribers: jhb, kevans.

Looks good to me, though I note the one historical curiosity inline.

lib/libc/gen/fdopendir.c
52

I was doing some archaeology and noticed that @jhb had dropped an early bailout almost identical to this in rG9f72c0322cff595213c2087d6d04928f72e23b0d / D312

This revision is now accepted and ready to land.Mon, Jul 7, 2:06 AM
lib/libc/gen/fdopendir.c
52

As noted in that review, the idea then was to reuse the check from _getdirentries(). Presumably the error case is not the one to optimize for, so detecting the error later is ok? That said, I think we don't call _getdirentries() in the unionfs case? Does the test fail without this change?

Also, if you add this back here, you need to remove the code that maps EINVAL from _getdirentries() to ENOTDIR as that mapping was added as part of the earlier commit.

lib/libc/gen/fdopendir.c
52

In the unionfs case, we call openat() which presumably will also return ENOTDIR if the fd is not associated with a directory.

I was surprised to see that the errno mapping was needed, though. POSIX doesn't have getdirentries(), but it does have posix_getdents() which is roughly equivalent and is required to set errno to ENOTDIR if the file descriptor is not associated with a directory. I'll look into changing getdirentries().

unresurrect the directory check

This revision now requires review to proceed.Tue, Jul 8, 6:46 PM
des marked 2 inline comments as done.
This revision is now accepted and ready to land.Tue, Jul 8, 6:46 PM
lib/libc/gen/fdopendir.c
52

I just discovered case where the test makes a difference. If the file descriptor is not associated with a directory, but also not open for reading, you get EBADF rather than ENOTDIR. This is the case when running the test in this review, because creat() only opens the file for writing. Rather than reinstate the check, though, I'll adjust the test.

This revision was automatically updated to reflect the committed changes.