Make sure Application::InitializeBase() when RLIMIT_NOFILE is set to "unlimited".

Refs #6257
This commit is contained in:
Gunnar Beutner 2014-05-26 07:35:07 +02:00
parent d66b4d587e
commit f9512dd495
1 changed files with 8 additions and 2 deletions

View File

@ -110,11 +110,17 @@ void Application::InitializeBase(void)
{
#ifndef _WIN32
rlimit rl;
if (getrlimit(RLIMIT_NOFILE, &rl) >= 0)
for (rlim_t i = 3; i < rl.rlim_max; i++) {
if (getrlimit(RLIMIT_NOFILE, &rl) >= 0) {
rlim_t maxfds = rl.rlim_max;
if (maxfds == RLIM_INFINITY)
maxfds = 65536;
for (rlim_t i = 3; i < maxfds; i++) {
if (close(i) >= 0)
std::cerr << "Closed FD " << i << " which we inherited from our parent process." << std::endl;
}
}
#endif /* _WIN32 */
Utility::ExecuteDeferredInitializers();