]> granicus.if.org Git - icinga2/commitdiff
Make sure Application::InitializeBase() when RLIMIT_NOFILE is set to "unlimited".
authorGunnar Beutner <gunnar@beutner.name>
Mon, 26 May 2014 05:35:07 +0000 (07:35 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Mon, 26 May 2014 05:40:47 +0000 (07:40 +0200)
Refs #6257

lib/base/application.cpp

index 92a1541522d734d4dd0b005eb6afac4d59b4938b..802089567cf0431d1e429014bf9c798177db3d66 100644 (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();