summaryrefslogtreecommitdiffstats
path: root/daemon
diff options
context:
space:
mode:
authorDim-P <Dim-P@users.noreply.github.com>2023-01-19 12:01:02 +0000
committerGitHub <noreply@github.com>2023-01-19 12:01:02 +0000
commit8ee7e8b26162c1c29e46c8894903b57d7bbd687f (patch)
treedaee30f6f2496446bd06539a317aba52a1de8568 /daemon
parentc1908d3163185cf65a139edeb11a165a10eca1e9 (diff)
Improve file descriptor closing loops (#14213)
* Add for_each_open_fd() and fix second instance of _SC_OPEN_MAX * Add argument to allow exclusion of file descriptors from closing * Fix clang error * Address review comments * Use close_range() if possible and replace macros with enums
Diffstat (limited to 'daemon')
-rw-r--r--daemon/main.c7
1 files changed, 2 insertions, 5 deletions
diff --git a/daemon/main.c b/daemon/main.c
index c19d9cc069..408b7a2ded 100644
--- a/daemon/main.c
+++ b/daemon/main.c
@@ -1700,15 +1700,12 @@ int main(int argc, char **argv) {
}
}
-#ifdef _SC_OPEN_MAX
if (close_open_fds == true) {
// close all open file descriptors, except the standard ones
// the caller may have left open files (lxc-attach has this issue)
- for(int fd = (int) (sysconf(_SC_OPEN_MAX) - 1); fd > 2; fd--)
- if(fd_is_valid(fd))
- close(fd);
+ for_each_open_fd(OPEN_FD_ACTION_CLOSE, OPEN_FD_EXCLUDE_STDIN | OPEN_FD_EXCLUDE_STDOUT | OPEN_FD_EXCLUDE_STDERR);
}
-#endif
+
if(!config_loaded) {
load_netdata_conf(NULL, 0);