2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-03 16:15:27 +00:00

The bug fix in socket.c 1.189 was less than ideal: if a socket

got wedged in a state where accept() always returns EBADF, the server would loop calling
internal_accept() repeatedly.  Implemented an alternative fix where a hard
error in accept() causes an event with a nonzero result code to be sent, and
the new socket object to be freed
This commit is contained in:
Andreas Gustafsson
2001-04-10 21:38:33 +00:00
parent 0e528248ab
commit a84cfaa3f2

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
/* $Id: socket.c,v 1.194 2001/03/06 01:23:03 bwelling Exp $ */ /* $Id: socket.c,v 1.195 2001/04/10 21:38:33 gson Exp $ */
#include <config.h> #include <config.h>
@@ -1627,7 +1627,6 @@ internal_accept(isc_task_t *me, isc_event_t *ev) {
ISC_SOCKADDR_LEN_T addrlen; ISC_SOCKADDR_LEN_T addrlen;
int fd; int fd;
isc_result_t result = ISC_R_SUCCESS; isc_result_t result = ISC_R_SUCCESS;
isc_boolean_t failed = ISC_FALSE;
UNUSED(me); UNUSED(me);
@@ -1674,7 +1673,11 @@ internal_accept(isc_task_t *me, isc_event_t *ev) {
fd = accept(sock->fd, &dev->newsocket->address.type.sa, fd = accept(sock->fd, &dev->newsocket->address.type.sa,
(void *)&addrlen); (void *)&addrlen);
if (fd < 0) { if (fd < 0) {
if (! SOFT_ERROR(errno)) { if (SOFT_ERROR(errno)) {
select_poke(sock->manager, sock->fd, SELECT_POKE_ACCEPT);
UNLOCK(&sock->lock);
return;
} else {
UNEXPECTED_ERROR(__FILE__, __LINE__, UNEXPECTED_ERROR(__FILE__, __LINE__,
"internal_accept: accept() %s: %s", "internal_accept: accept() %s: %s",
isc_msgcat_get(isc_msgcat, isc_msgcat_get(isc_msgcat,
@@ -1682,8 +1685,8 @@ internal_accept(isc_task_t *me, isc_event_t *ev) {
ISC_MSG_FAILED, ISC_MSG_FAILED,
"failed"), "failed"),
strerror(errno)); strerror(errno));
result = ISC_R_UNEXPECTED;
} }
failed = ISC_TRUE;
} else { } else {
if (addrlen == 0) { if (addrlen == 0) {
UNEXPECTED_ERROR(__FILE__, __LINE__, UNEXPECTED_ERROR(__FILE__, __LINE__,
@@ -1692,7 +1695,8 @@ internal_accept(isc_task_t *me, isc_event_t *ev) {
"remote address"); "remote address");
(void)close(fd); (void)close(fd);
failed = ISC_TRUE; fd = -1;
result = ISC_R_UNEXPECTED;
} else if (dev->newsocket->address.type.sa.sa_family != } else if (dev->newsocket->address.type.sa.sa_family !=
sock->pf) sock->pf)
{ {
@@ -1704,19 +1708,16 @@ internal_accept(isc_task_t *me, isc_event_t *ev) {
type.sa.sa_family, type.sa.sa_family,
sock->pf); sock->pf);
(void)close(fd); (void)close(fd);
failed = ISC_TRUE; fd = -1;
result = ISC_R_UNEXPECTED;
} }
} }
if (failed) { if (fd != -1) {
select_poke(sock->manager, sock->fd, SELECT_POKE_ACCEPT); dev->newsocket->address.length = addrlen;
UNLOCK(&sock->lock); dev->newsocket->pf = sock->pf;
return;
} }
dev->newsocket->address.length = addrlen;
dev->newsocket->pf = sock->pf;
/* /*
* Pull off the done event. * Pull off the done event.
*/ */
@@ -1765,6 +1766,9 @@ internal_accept(isc_task_t *me, isc_event_t *ev) {
UNLOCK(&manager->lock); UNLOCK(&manager->lock);
if (fd == -1)
isc_socket_detach(&dev->newsocket);
/* /*
* Fill in the done event details and send it off. * Fill in the done event details and send it off.
*/ */