From 53f5a603ce68d0efb3bf2e95a34365078e967d1d Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Tue, 23 Aug 2016 05:11:22 +0200 Subject: [PATCH] Implement an environment variable to keep Icinga from closing FDs on startup fixes #12510 --- icinga-app/icinga.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp index f50450525..0fea800ba 100644 --- a/icinga-app/icinga.cpp +++ b/icinga-app/icinga.cpp @@ -706,20 +706,22 @@ VOID WINAPI ServiceMain(DWORD argc, LPSTR *argv) int main(int argc, char **argv) { #ifndef _WIN32 - rlimit rl; - if (getrlimit(RLIMIT_NOFILE, &rl) >= 0) { - rlim_t maxfds = rl.rlim_max; + if (!getenv("ICINGA2_KEEP_FDS")) { + rlimit rl; + if (getrlimit(RLIMIT_NOFILE, &rl) >= 0) { + rlim_t maxfds = rl.rlim_max; - if (maxfds == RLIM_INFINITY) - maxfds = 65536; + if (maxfds == RLIM_INFINITY) + maxfds = 65536; - for (rlim_t i = 3; i < maxfds; i++) { - int rc = close(i); + for (rlim_t i = 3; i < maxfds; i++) { + int rc = close(i); #ifdef I2_DEBUG - if (rc >= 0) - std::cerr << "Closed FD " << i << " which we inherited from our parent process." << std::endl; + if (rc >= 0) + std::cerr << "Closed FD " << i << " which we inherited from our parent process." << std::endl; #endif /* I2_DEBUG */ + } } } #endif /* _WIN32 */ -- 2.40.0