diff options
| author | Lennart Poettering <lennart@poettering.net> | 2009-10-15 03:33:57 +0200 | 
|---|---|---|
| committer | Lennart Poettering <lennart@poettering.net> | 2009-10-15 03:33:57 +0200 | 
| commit | 81d74c9df801174012a2fb7aebc8569db85faf0c (patch) | |
| tree | a316b914c73e3cd1cd59d4ba8ef7766b3ff501cf | |
| parent | 5e5035cc89ee6ddd62c626f34bf002522cfb18a4 (diff) | |
fix loop exit in close_allv()
| -rw-r--r-- | libasyncns/asyncns.c | 23 | 
1 files changed, 14 insertions, 9 deletions
diff --git a/libasyncns/asyncns.c b/libasyncns/asyncns.c index 13a21f2..0161400 100644 --- a/libasyncns/asyncns.c +++ b/libasyncns/asyncns.c @@ -214,7 +214,7 @@ static char *strndup(const char *s, size_t l) {  static int close_allv(const int except_fds[]) {      struct rlimit rl; -    int fd; +    int fd, maxfd;  #ifdef __linux__ @@ -284,18 +284,23 @@ static int close_allv(const int except_fds[]) {  #endif -    if (getrlimit(RLIMIT_NOFILE, &rl) < 0) -        return -1; - -    for (fd = 0; fd < (int) rl.rlim_max; fd++) { -        int i; +    if (getrlimit(RLIMIT_NOFILE, &rl) > 0) +        maxfd = (int) rl.rlim_max; +    else +        maxfd = sysconf(_SC_OPEN_MAX); -        if (fd <= 3) -            continue; +    for (fd = 3; fd < maxfd; fd++) { +        int i, found; +        found = 0;          for (i = 0; except_fds[i] >= 0; i++) -            if (except_fds[i] == fd) +            if (except_fds[i] == fd) { +                found = 1;                  continue; +            } + +        if (found) +            continue;          if (close(fd) < 0 && errno != EBADF)              return -1;  | 
