BUG/MINOR: dns: Don't try to get the server lock if it's already held.
dns_link_resolution() can be called with the server lock already held, so
don't attempt to lock it again in that case.
diff --git a/include/proto/dns.h b/include/proto/dns.h
index c3e3846..3ad79c3 100644
--- a/include/proto/dns.h
+++ b/include/proto/dns.h
@@ -40,7 +40,7 @@
void **newip, short *newip_sin_family,
void *owner);
-int dns_link_resolution(void *requester, int requester_type);
+int dns_link_resolution(void *requester, int requester_type, int requester_locked);
void dns_unlink_resolution(struct dns_requester *requester);
void dns_trigger_resolution(struct dns_requester *requester);
diff --git a/src/dns.c b/src/dns.c
index 6b87460..1d12c84 100644
--- a/src/dns.c
+++ b/src/dns.c
@@ -550,8 +550,10 @@
char hostname[DNS_MAX_NAME_SIZE];
if (dns_dn_label_to_str(item->target, item->data_len+1,
- hostname, DNS_MAX_NAME_SIZE) == -1)
+ hostname, DNS_MAX_NAME_SIZE) == -1) {
+ SPIN_UNLOCK(SERVER_LOCK, &srv->lock);
continue;
+ }
msg = update_server_fqdn(srv, hostname, "SRV record", 1);
if (msg)
send_log(srv->proxy, LOG_NOTICE, "%s", msg);
@@ -1307,7 +1309,7 @@
/* Links a requester (a server or a dns_srvrq) with a resolution. It returns 0
* on success, -1 otherwise.
*/
-int dns_link_resolution(void *requester, int requester_type)
+int dns_link_resolution(void *requester, int requester_type, int requester_locked)
{
struct dns_resolution *res = NULL;
struct dns_requester *req;
@@ -1345,10 +1347,12 @@
goto err;
if (srv) {
- SPIN_LOCK(SERVER_LOCK, &srv->lock);
+ if (!requester_locked)
+ SPIN_LOCK(SERVER_LOCK, &srv->lock);
if (srv->dns_requester == NULL) {
if ((req = calloc(1, sizeof(*req))) == NULL) {
- SPIN_UNLOCK(SERVER_LOCK, &srv->lock);
+ if (!requester_locked)
+ SPIN_UNLOCK(SERVER_LOCK, &srv->lock);
goto err;
}
req->owner = &srv->obj_type;
@@ -1356,7 +1360,8 @@
}
else
req = srv->dns_requester;
- SPIN_UNLOCK(SERVER_LOCK, &srv->lock);
+ if (!requester_locked)
+ SPIN_UNLOCK(SERVER_LOCK, &srv->lock);
}
else if (srvrq) {
if (srvrq->dns_requester == NULL) {
@@ -1905,14 +1910,14 @@
if (srv->srvrq && !srv->srvrq->resolvers) {
srv->srvrq->resolvers = srv->resolvers;
- if (dns_link_resolution(srv->srvrq, OBJ_TYPE_SRVRQ) == -1) {
+ if (dns_link_resolution(srv->srvrq, OBJ_TYPE_SRVRQ, 0) == -1) {
Alert("config : %s '%s' : unable to set DNS resolution for server '%s'.\n",
proxy_type_str(px), px->id, srv->id);
err_code |= (ERR_ALERT|ERR_ABORT);
continue;
}
}
- if (dns_link_resolution(srv, OBJ_TYPE_SERVER) == -1) {
+ if (dns_link_resolution(srv, OBJ_TYPE_SERVER, 0) == -1) {
Alert("config : %s '%s', unable to set DNS resolution for server '%s'.\n",
proxy_type_str(px), px->id, srv->id);
err_code |= (ERR_ALERT|ERR_ABORT);
diff --git a/src/server.c b/src/server.c
index ed78ca5..adc9fd4 100644
--- a/src/server.c
+++ b/src/server.c
@@ -3818,7 +3818,7 @@
if (!srv->hostname || !srv->hostname_dn)
goto err;
- if (dns_link_resolution(srv, OBJ_TYPE_SERVER) == -1)
+ if (dns_link_resolution(srv, OBJ_TYPE_SERVER, 1) == -1)
goto err;
end: