summaryrefslogtreecommitdiff
path: root/src/irmd
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@ugent.be>2017-08-04 10:29:56 +0000
committerSander Vrijders <sander.vrijders@ugent.be>2017-08-04 10:29:56 +0000
commit7729199645eb2c14d7b8a5329eb441f14fe7729f (patch)
tree5c046925f2af509f2a2db255562fad418a3271a0 /src/irmd
parent9017e3006c1e1246de5291f13319a763fd440e2f (diff)
parent0fe8d5aa50fcadc3b4eef65b2833944a76eb8f3e (diff)
downloadouroboros-7729199645eb2c14d7b8a5329eb441f14fe7729f.tar.gz
ouroboros-7729199645eb2c14d7b8a5329eb441f14fe7729f.zip
Merged in dstaesse/ouroboros/testing-irmd (pull request #541)
irmd: Release lock before ipcp_query
Diffstat (limited to 'src/irmd')
-rw-r--r--src/irmd/main.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/irmd/main.c b/src/irmd/main.c
index 63ae6b13..912234d6 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -232,10 +232,14 @@ static struct ipcp_entry * get_ipcp_entry_by_name(const char * name)
static struct ipcp_entry * get_ipcp_by_dst_name(const char * name)
{
- struct list_head * p = NULL;
- uint8_t * hash;
+ struct list_head * p;
+ struct list_head * h;
+ uint8_t * hash;
+ pid_t api;
- list_for_each(p, &irmd.ipcps) {
+ pthread_rwlock_rdlock(&irmd.reg_lock);
+
+ list_for_each_safe(p, h, &irmd.ipcps) {
struct ipcp_entry * e = list_entry(p, struct ipcp_entry, next);
if (e->dif_name == NULL)
continue;
@@ -246,14 +250,22 @@ static struct ipcp_entry * get_ipcp_by_dst_name(const char * name)
str_hash(e->dir_hash_algo, hash, name);
- if (ipcp_query(e->api, hash, IPCP_HASH_LEN(e)) == 0) {
+ api = e->api;
+
+ pthread_rwlock_unlock(&irmd.reg_lock);
+
+ if (ipcp_query(api, hash, IPCP_HASH_LEN(e)) == 0) {
free(hash);
return e;
}
free(hash);
+
+ pthread_rwlock_rdlock(&irmd.reg_lock);
}
+ pthread_rwlock_unlock(&irmd.reg_lock);
+
return NULL;
}
@@ -1099,16 +1111,12 @@ static int flow_alloc(pid_t api,
int state;
uint8_t * hash;
- pthread_rwlock_rdlock(&irmd.reg_lock);
-
ipcp = get_ipcp_by_dst_name(dst);
if (ipcp == NULL) {
- pthread_rwlock_unlock(&irmd.reg_lock);
log_info("Destination %s unreachable.", dst);
return -1;
}
- pthread_rwlock_unlock(&irmd.reg_lock);
pthread_rwlock_wrlock(&irmd.flows_lock);
port_id = bmp_allocate(irmd.port_ids);
if (!bmp_is_id_valid(irmd.port_ids, port_id)) {