summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2009-10-17 21:37:11 +0200
committerLennart Poettering <lennart@poettering.net>2009-10-17 21:37:11 +0200
commit8312ea47f754bc0962f4c92d8aa6a77c0d5c43a0 (patch)
tree430eae4510cb7f55f6e46d0ddf581fdd46db9260
parentd6381960e981c5f56d4fb1b3360fac4ef808ddac (diff)
dfork: honour _SC_OPEN_MAX
-rw-r--r--libdaemon/dfork.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/libdaemon/dfork.c b/libdaemon/dfork.c
index 62469bb..5f163fd 100644
--- a/libdaemon/dfork.c
+++ b/libdaemon/dfork.c
@@ -479,7 +479,7 @@ int daemon_close_all(int except_fd, ...) {
/** Same as daemon_close_all but takes an array of fds, terminated by -1 */
int daemon_close_allv(const int except_fds[]) {
struct rlimit rl;
- int fd;
+ int fd, maxfd;
#ifdef __linux__
int saved_errno;
@@ -549,15 +549,14 @@ int daemon_close_allv(const int except_fds[]) {
#endif
- if (getrlimit(RLIMIT_NOFILE, &rl) < 0)
- return -1;
+ if (getrlimit(RLIMIT_NOFILE, &rl) > 0)
+ maxfd = (int) rl.rlim_max;
+ else
+ maxfd = sysconf(_SC_OPEN_MAX);
- for (fd = 0; fd < (int) rl.rlim_max; fd++) {
+ for (fd = 3; fd < maxfd; fd++) {
int i, found;
- if (fd <= 3)
- continue;
-
if (fd == _daemon_retval_pipe[1])
continue;