Commit 191f2f79 authored by venaas's avatar venaas Committed by venaas
Browse files

added some locking to handle server removal, think need to do refcounting for configs too

git-svn-id: https://svn.testnett.uninett.no/radsecproxy/trunk@400 e88ac4ed-0b26-0410-9574-a7f39faa03bf
parent 8c898f47
...@@ -544,22 +544,35 @@ struct client *addclient(struct clsrvconf *conf, uint8_t lock) { ...@@ -544,22 +544,35 @@ struct client *addclient(struct clsrvconf *conf, uint8_t lock) {
return new; return new;
} }
void removeclientrqs_sendrq_freeserver_lock(uint8_t wantlock) {
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
if (wantlock)
pthread_mutex_lock(&lock);
else
pthread_mutex_unlock(&lock);
}
void removeclientrqs(struct client *client) { void removeclientrqs(struct client *client) {
struct request *rq; struct request *rq;
struct rqout *rqout; struct rqout *rqout;
int i; int i;
removeclientrqs_sendrq_freeserver_lock(1);
for (i = 0; i < MAX_REQUESTS; i++) { for (i = 0; i < MAX_REQUESTS; i++) {
rq = client->rqs[i]; rq = client->rqs[i];
if (!rq) if (!rq)
continue; continue;
rqout = rq->to->requests + rq->newid; if (rq->to) {
pthread_mutex_lock(rqout->lock); rqout = rq->to->requests + rq->newid;
if (rqout->rq == rq) /* still pointing to our request */ pthread_mutex_lock(rqout->lock);
freerqoutdata(rqout); if (rqout->rq == rq) /* still pointing to our request */
pthread_mutex_unlock(rqout->lock); freerqoutdata(rqout);
pthread_mutex_unlock(rqout->lock);
}
freerq(rq); freerq(rq);
} }
removeclientrqs_sendrq_freeserver_lock(0);
} }
void removeclient(struct client *client) { void removeclient(struct client *client) {
...@@ -585,9 +598,12 @@ void freeserver(struct server *server, uint8_t destroymutex) { ...@@ -585,9 +598,12 @@ void freeserver(struct server *server, uint8_t destroymutex) {
if (!server) if (!server)
return; return;
removeclientrqs_sendrq_freeserver_lock(1);
if (server->requests) { if (server->requests) {
rqout = server->requests; rqout = server->requests;
for (end = rqout + MAX_REQUESTS; rqout < end; rqout++) { for (end = rqout + MAX_REQUESTS; rqout < end; rqout++) {
if (rqout->rq)
rqout->rq->to = NULL;
freerqoutdata(rqout); freerqoutdata(rqout);
pthread_mutex_destroy(rqout->lock); pthread_mutex_destroy(rqout->lock);
free(rqout->lock); free(rqout->lock);
...@@ -604,6 +620,7 @@ void freeserver(struct server *server, uint8_t destroymutex) { ...@@ -604,6 +620,7 @@ void freeserver(struct server *server, uint8_t destroymutex) {
pthread_cond_destroy(&server->newrq_cond); pthread_cond_destroy(&server->newrq_cond);
pthread_mutex_destroy(&server->newrq_mutex); pthread_mutex_destroy(&server->newrq_mutex);
} }
removeclientrqs_sendrq_freeserver_lock(0);
free(server); free(server);
} }
...@@ -910,7 +927,12 @@ void freerqoutdata(struct rqout *rqout) { ...@@ -910,7 +927,12 @@ void freerqoutdata(struct rqout *rqout) {
void sendrq(struct request *rq) { void sendrq(struct request *rq) {
int i, start; int i, start;
struct server *to = rq->to; struct server *to;
removeclientrqs_sendrq_freeserver_lock(1);
to = rq->to;
if (!to)
goto errexit;
start = to->conf->statusserver ? 1 : 0; start = to->conf->statusserver ? 1 : 0;
pthread_mutex_lock(&to->newrq_mutex); pthread_mutex_lock(&to->newrq_mutex);
...@@ -971,6 +993,7 @@ void sendrq(struct request *rq) { ...@@ -971,6 +993,7 @@ void sendrq(struct request *rq) {
} }
pthread_mutex_unlock(&to->newrq_mutex); pthread_mutex_unlock(&to->newrq_mutex);
removeclientrqs_sendrq_freeserver_lock(0);
return; return;
errexit: errexit:
...@@ -978,6 +1001,7 @@ void sendrq(struct request *rq) { ...@@ -978,6 +1001,7 @@ void sendrq(struct request *rq) {
rmclientrq(rq, rq->msg->id); rmclientrq(rq, rq->msg->id);
freerq(rq); freerq(rq);
pthread_mutex_unlock(&to->newrq_mutex); pthread_mutex_unlock(&to->newrq_mutex);
removeclientrqs_sendrq_freeserver_lock(0);
} }
void sendreply(struct request *rq) { void sendreply(struct request *rq) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment