-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Fix macOS dir behaviour by providing EINTR handling #48694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth adding a comment to the effect that EINTR isn't documented but has been shown to happen in practice. Otherwise, LGTM. Thanks for the fix.
|
Added comments. I'm pretty sure readdir_r is being used on macOS, so I didn't guard readdir too. |
| int error; | ||
|
|
||
| // EINTR isn't documented, happens in practice on macOS. | ||
| while ((error = readdir_r(dir, entry, &result)) && error == EINTR); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are you sure the EINTR is returned as the return value and not in errno?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a reliable repro, but I can look in xnu source. I can adapt it so it checks errno.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like readdir_r sets the return value to whatever is in errno?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've read a few man pages of different OSes and there seems to be little consistency regarding this.
If using errno works on macOS then I'd prefer that since it's what we use everywhere else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If using errno works on macOS then I'd prefer that since it's what we use everywhere else.
Except this API explicitly says errors are returned rather than surfacing through errno. Is there an example man page that says readdir_r sets errno? What happens if a readdir_r implementation doesn't touch errno at all, errno retains an EINTR value from prior to the readdir_r call, and readdir_r hits another error... might we end up in an infinite loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can change the code back to checking the return code :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before you do, I'd like to hear from @akoeplinger :) I was actually asking questions rather than stating things that must happen ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specifically, on macOS/FreeBSD, it looks like this: https://opensource.apple.com/source/Libc/Libc-1439.40.11/gen/FreeBSD/readdir.c.auto.html
|
Hello @akoeplinger! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
|
Test failures are due to #48751. |
Fixes #47584