From 881404945f12fdcb7b017540d68b3b9ff2572d5a Mon Sep 17 00:00:00 2001 From: jhb Date: Mon, 5 Mar 2007 19:39:51 +0000 Subject: Only reject file descriptors higher than FD_SETSIZE if we are not using poll(2) or kqueue(2). Previously we rejected fd's higher than FD_SETSIZE for kevent(2), and larger than sysconf(_SC_OPEN_MAX) for poll(2). However, the check for poll(2) wasn't really needed. open(2) and socket(2) won't return an fd you can't pass to either poll(2) or kevent(2). This fixes a but where gethostbyname() would fail if you had more than 1023 files open in a process. MFC after: 1 week Reviewed by: ume Found by: ps --- lib/libc/resolv/res_send.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/libc/resolv/res_send.c b/lib/libc/resolv/res_send.c index b7f3f6c..455599e 100644 --- a/lib/libc/resolv/res_send.c +++ b/lib/libc/resolv/res_send.c @@ -124,10 +124,8 @@ __FBSDID("$FreeBSD$"); #define EXT(res) ((res)->_u._ext) -#ifndef USE_POLL +#if !defined(USE_POLL) && !defined(USE_KQUEUE) static const int highestFD = FD_SETSIZE - 1; -#else -static int highestFD = 0; #endif /* Forward. */ @@ -305,10 +303,6 @@ res_nsend(res_state statp, #endif char abuf[NI_MAXHOST]; -#ifdef USE_POLL - highestFD = sysconf(_SC_OPEN_MAX) - 1; -#endif - /* No name servers or res_init() failure */ if (statp->nscount == 0 || EXT(statp).ext == NULL) { errno = ESRCH; @@ -659,10 +653,12 @@ send_vc(res_state statp, res_nclose(statp); statp->_vcsock = _socket(nsap->sa_family, SOCK_STREAM, 0); +#if !defined(USE_POLL) && !defined(USE_KQUEUE) if (statp->_vcsock > highestFD) { res_nclose(statp); errno = ENOTSOCK; } +#endif if (statp->_vcsock < 0) { switch (errno) { case EPROTONOSUPPORT: @@ -837,10 +833,12 @@ send_dg(res_state statp, if (EXT(statp).nssocks[ns] == -1) { EXT(statp).nssocks[ns] = _socket(nsap->sa_family, SOCK_DGRAM, 0); +#if !defined(USE_POLL) && !defined(USE_KQUEUE) if (EXT(statp).nssocks[ns] > highestFD) { res_nclose(statp); errno = ENOTSOCK; } +#endif if (EXT(statp).nssocks[ns] < 0) { switch (errno) { case EPROTONOSUPPORT: -- cgit v1.1