summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@intec.ugent.be>2016-08-24 22:13:10 +0200
committerdimitri staessens <dimitri.staessens@intec.ugent.be>2016-08-25 08:31:34 +0200
commitc85dac656cfea758ed582508d61a5d9eb6bd7bf9 (patch)
tree12018e6fae0f770b175b505a9b3d94b6a3a98e58 /src
parent9c0c55198c2406fea6be189e1ec6b3ac3cc565fc (diff)
downloadouroboros-c85dac656cfea758ed582508d61a5d9eb6bd7bf9.tar.gz
ouroboros-c85dac656cfea758ed582508d61a5d9eb6bd7bf9.zip
irmd: Fix bad lock
Diffstat (limited to 'src')
-rw-r--r--src/irmd/main.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/irmd/main.c b/src/irmd/main.c
index 8ac645df..5f793afd 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -425,7 +425,7 @@ static int enroll_ipcp(pid_t api,
return -1;
}
- pthread_rwlock_rdlock(&irmd->reg_lock);
+ pthread_rwlock_wrlock(&irmd->reg_lock);
entry = get_ipcp_entry_by_api(api);
if (entry == NULL) {
@@ -435,6 +435,13 @@ static int enroll_ipcp(pid_t api,
return -1;
}
+ if (entry->dif_name != NULL) {
+ pthread_rwlock_unlock(&irmd->reg_lock);
+ pthread_rwlock_unlock(&irmd->state_lock);
+ LOG_ERR("IPCP in wrong state");
+ return -1;
+ }
+
entry->dif_name = strdup(dif_name);
if (entry->dif_name == NULL) {
pthread_rwlock_unlock(&irmd->reg_lock);
@@ -443,7 +450,12 @@ static int enroll_ipcp(pid_t api,
return -1;
}
+ pthread_rwlock_unlock(&irmd->reg_lock);
+ pthread_rwlock_unlock(&irmd->state_lock);
+
if (ipcp_enroll(api, dif_name)) {
+ pthread_rwlock_rdlock(&irmd->state_lock);
+ pthread_rwlock_wrlock(&irmd->reg_lock);
free(entry->dif_name);
entry->dif_name = NULL;
pthread_rwlock_unlock(&irmd->reg_lock);
@@ -452,11 +464,8 @@ static int enroll_ipcp(pid_t api,
return -1;
}
- pthread_rwlock_unlock(&irmd->reg_lock);
- pthread_rwlock_unlock(&irmd->state_lock);
-
LOG_INFO("Enrolled IPCP %d in DIF %s.",
- entry->api, dif_name);
+ api, dif_name);
return 0;
}