2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 14:07:59 +00:00

Move the lock from internal_{accept,connect,recv,send} to global level to protect more socket variables

This commit is contained in:
Ondřej Surý
2019-07-04 16:10:19 +02:00
committed by Ondřej Surý
parent 43f3b3211f
commit 9808d7360e

View File

@@ -2778,10 +2778,8 @@ internal_accept(isc__socket_t *sock) {
INSIST(VALID_SOCKET(sock)); INSIST(VALID_SOCKET(sock));
LOCK(&sock->lock);
if (sock->fd < 0) { if (sock->fd < 0) {
/* Socket is gone */ /* Socket is gone */
UNLOCK(&sock->lock);
return; return;
} }
socket_log(sock, NULL, TRACE, socket_log(sock, NULL, TRACE,
@@ -2800,7 +2798,6 @@ internal_accept(isc__socket_t *sock) {
dev = ISC_LIST_HEAD(sock->accept_list); dev = ISC_LIST_HEAD(sock->accept_list);
if (dev == NULL) { if (dev == NULL) {
unwatch_fd(thread, sock->fd, SELECT_POKE_ACCEPT); unwatch_fd(thread, sock->fd, SELECT_POKE_ACCEPT);
UNLOCK(&sock->lock);
return; return;
} }
@@ -2916,11 +2913,10 @@ internal_accept(isc__socket_t *sock) {
/* /*
* Poke watcher if there are more pending accepts. * Poke watcher if there are more pending accepts.
*/ */
if (ISC_LIST_EMPTY(sock->accept_list)) if (ISC_LIST_EMPTY(sock->accept_list)) {
unwatch_fd(thread, sock->fd, unwatch_fd(thread, sock->fd,
SELECT_POKE_ACCEPT); SELECT_POKE_ACCEPT);
}
UNLOCK(&sock->lock);
if (fd != -1) { if (fd != -1) {
result = make_nonblock(fd); result = make_nonblock(fd);
@@ -3017,7 +3013,6 @@ internal_accept(isc__socket_t *sock) {
soft_error: soft_error:
watch_fd(thread, sock->fd, SELECT_POKE_ACCEPT); watch_fd(thread, sock->fd, SELECT_POKE_ACCEPT);
UNLOCK(&sock->lock);
inc_stats(manager->stats, sock->statsindex[STATID_ACCEPTFAIL]); inc_stats(manager->stats, sock->statsindex[STATID_ACCEPTFAIL]);
return; return;
@@ -3029,10 +3024,8 @@ internal_recv(isc__socket_t *sock) {
INSIST(VALID_SOCKET(sock)); INSIST(VALID_SOCKET(sock));
LOCK(&sock->lock);
if (sock->fd < 0) { if (sock->fd < 0) {
/* Socket is gone */ /* Socket is gone */
UNLOCK(&sock->lock);
return; return;
} }
dev = ISC_LIST_HEAD(sock->recv_list); dev = ISC_LIST_HEAD(sock->recv_list);
@@ -3079,7 +3072,6 @@ internal_recv(isc__socket_t *sock) {
unwatch_fd(&sock->manager->threads[sock->threadid], sock->fd, unwatch_fd(&sock->manager->threads[sock->threadid], sock->fd,
SELECT_POKE_READ); SELECT_POKE_READ);
} }
UNLOCK(&sock->lock);
} }
static void static void
@@ -3088,10 +3080,8 @@ internal_send(isc__socket_t *sock) {
INSIST(VALID_SOCKET(sock)); INSIST(VALID_SOCKET(sock));
LOCK(&sock->lock);
if (sock->fd < 0) { if (sock->fd < 0) {
/* Socket is gone */ /* Socket is gone */
UNLOCK(&sock->lock);
return; return;
} }
dev = ISC_LIST_HEAD(sock->send_list); dev = ISC_LIST_HEAD(sock->send_list);
@@ -3125,7 +3115,6 @@ internal_send(isc__socket_t *sock) {
unwatch_fd(&sock->manager->threads[sock->threadid], unwatch_fd(&sock->manager->threads[sock->threadid],
sock->fd, SELECT_POKE_WRITE); sock->fd, SELECT_POKE_WRITE);
} }
UNLOCK(&sock->lock);
} }
/* /*
@@ -3166,6 +3155,7 @@ process_fd(isc__socketthread_t *thread, int fd, bool readable,
return; return;
} }
LOCK(&sock->lock);
if (readable) { if (readable) {
if (sock->listener) { if (sock->listener) {
internal_accept(sock); internal_accept(sock);
@@ -3181,6 +3171,7 @@ process_fd(isc__socketthread_t *thread, int fd, bool readable,
internal_send(sock); internal_send(sock);
} }
} }
UNLOCK(&sock->lock);
UNLOCK(&thread->fdlock[lockid]); UNLOCK(&thread->fdlock[lockid]);
if (isc_refcount_decrement(&sock->references) == 1) { if (isc_refcount_decrement(&sock->references) == 1) {
@@ -4875,8 +4866,6 @@ internal_connect(isc__socket_t *sock) {
INSIST(VALID_SOCKET(sock)); INSIST(VALID_SOCKET(sock));
LOCK(&sock->lock);
/* /*
* Get the first item off the connect list. * Get the first item off the connect list.
* If it is empty, unlock the socket and return. * If it is empty, unlock the socket and return.
@@ -4907,7 +4896,6 @@ internal_connect(isc__socket_t *sock) {
*/ */
if (SOFT_ERROR(errno) || errno == EINPROGRESS) { if (SOFT_ERROR(errno) || errno == EINPROGRESS) {
sock->connecting = 1; sock->connecting = 1;
UNLOCK(&sock->lock);
return; return;
} }
@@ -4960,8 +4948,6 @@ internal_connect(isc__socket_t *sock) {
finish: finish:
unwatch_fd(&sock->manager->threads[sock->threadid], sock->fd, unwatch_fd(&sock->manager->threads[sock->threadid], sock->fd,
SELECT_POKE_CONNECT); SELECT_POKE_CONNECT);
UNLOCK(&sock->lock);
} }
isc_result_t isc_result_t