Skip to content

Commit

Permalink
Implement an environment variable to keep Icinga from closing FDs on …
Browse files Browse the repository at this point in the history
…startup

fixes #12510
  • Loading branch information
gunnarbeutner committed Aug 23, 2016
1 parent 210fc4f commit ed5c8dd
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions icinga-app/icinga.cpp
Expand Up @@ -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 */
Expand Down

0 comments on commit ed5c8dd

Please sign in to comment.