Skip to content

don't rely on getdtablesize() #2586

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

Merged
merged 1 commit into from
Dec 12, 2019
Merged

don't rely on getdtablesize() #2586

merged 1 commit into from
Dec 12, 2019

Conversation

weissi
Copy link
Contributor

@weissi weissi commented Dec 12, 2019

Android and possibly other UNIX systems lack getdtablesize() so let's
try to use a better way of estimating the file descriptors we need to
close post-fork, pre-exec by listing /proc/self/fd. If that fails, we
fall back on getdtablesize or as a last resort a hard-coded 4096.

@weissi weissi requested review from millenomi and compnerd December 12, 2019 12:45
@weissi
Copy link
Contributor Author

weissi commented Dec 12, 2019

@swift-ci please test

1 similar comment
@weissi
Copy link
Contributor Author

weissi commented Dec 12, 2019

@swift-ci please test

@weissi
Copy link
Contributor Author

weissi commented Dec 12, 2019

@swift-ci please test

@weissi
Copy link
Contributor Author

weissi commented Dec 12, 2019

@swift-ci please test

2 similar comments
@weissi
Copy link
Contributor Author

weissi commented Dec 12, 2019

@swift-ci please test

@weissi
Copy link
Contributor Author

weissi commented Dec 12, 2019

@swift-ci please test

Android and possibly other UNIX systems lack getdtablesize() so let's
try to use a better way of estimating the file descriptors we need to
close post-fork, pre-exec by listing /proc/self/fd. If that fails, we
fall back on getdtablesize or as a last resort a hard-coded 4096.
@weissi
Copy link
Contributor Author

weissi commented Dec 12, 2019

@swift-ci please test

2 similar comments
@weissi
Copy link
Contributor Author

weissi commented Dec 12, 2019

@swift-ci please test

@weissi
Copy link
Contributor Author

weissi commented Dec 12, 2019

@swift-ci please test

}

return highestFDSoFar
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would
return try? FileManager.default.contentsOfDirectory(atPath: "/proc/self/fd").compactMap { CInt($0) }.max()

be a bit simpler?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spevans I wasn't sure about the guarantees around symlinks as in does it follow symlinks, does it not, what happens if the symlink is a broken link, etc. Therefore I went for readdir, happy to change if we think it's fine.

@compnerd
Copy link
Member

Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like @spevans' suggestion, but, lets get this merged to repair the build, and we can do that in a follow up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants