Page MenuHomeFreeBSD

opendir, fdopendir: Add tests, improve robustness.
AcceptedPublic

Authored by des on Wed, Jul 2, 11:51 AM.

Details

Reviewers
kevans
markj
Group Reviewers
Klara
Summary
  • Add test cases for opendir() and fdopendir().
  • Make fdopendir() fail early if the file descriptor is invalid or not associated with a directory.
  • 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 65175
Build 62058: 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
54

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
54

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.