Skip to content
Snippets Groups Projects
Commit d8554fbd authored by Tim Wickberg's avatar Tim Wickberg
Browse files

Only close the current range of open file descriptors.

Match up to lowered open file limits used by 18b2f4ff.

Bug 10254.
parent f2467109
No related branches found
No related tags found
No related merge requests found
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#define _FD_H #define _FD_H
#include <fcntl.h> #include <fcntl.h>
#include <sys/resource.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
...@@ -48,9 +49,14 @@ ...@@ -48,9 +49,14 @@
/* close all FDs >= a specified value */ /* close all FDs >= a specified value */
static inline void closeall(int fd) static inline void closeall(int fd)
{ {
int fdlimit = sysconf(_SC_OPEN_MAX); struct rlimit rlim;
while (fd < fdlimit) if (getrlimit(RLIMIT_NOFILE, &rlim) < 0) {
error("getrlimit(RLIMIT_NOFILE): %m");
rlim.rlim_cur = 4096;
}
while (fd < rlim.rlim_cur)
close(fd++); close(fd++);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment