From 23ee3bf9bc54c2305a3b9dfe89ac1a03fec1af1d Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 21 Feb 2007 15:46:30 +0000 Subject: [PATCH] Check for FD_SETSIZE limit --- sapi/cgi/fastcgi.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/sapi/cgi/fastcgi.c b/sapi/cgi/fastcgi.c index 639d348a7d..3ac12a2def 100644 --- a/sapi/cgi/fastcgi.c +++ b/sapi/cgi/fastcgi.c @@ -757,18 +757,23 @@ int fcgi_accept_request(fcgi_request *req) break; #else if (req->fd >= 0) { - struct timeval tv = {5,0}; - fd_set set; + if (req->fd < FD_SETSIZE) { + struct timeval tv = {5,0}; + fd_set set; - FD_ZERO(&set); - FD_SET(req->fd, &set); + FD_ZERO(&set); + FD_SET(req->fd, &set); try_again: - errno = 0; - if (select(req->fd + 1, &set, NULL, NULL, &tv) >= 0 && FD_ISSET(req->fd, &set)) { - break; + errno = 0; + if (select(req->fd + 1, &set, NULL, NULL, &tv) >= 0 && FD_ISSET(req->fd, &set)) { + break; + } + if (errno == EINTR) goto try_again; + fcgi_close(req, 1, 0); + } else { + fprintf(stderr, "Too many open file descriptors. FD_SETSIZE limit exceeded."); + fcgi_close(req, 1, 0); } - if (errno == EINTR) goto try_again; - fcgi_close(req, 1, 0); } #endif } -- 2.50.1