diff options
author | Sander Vrijders <sander.vrijders@intec.ugent.be> | 2016-08-25 08:35:53 +0200 |
---|---|---|
committer | Sander Vrijders <sander.vrijders@intec.ugent.be> | 2016-08-25 08:35:53 +0200 |
commit | 5b74bb43d36624c4cfb81d5b37833ea241061b26 (patch) | |
tree | 5f8beaf7290fc4d5b65c1acc27f7bc75e7ed6b55 /src | |
parent | 103325209373f0aec818efd775f91243eb912a33 (diff) | |
parent | 7147313663c738c87ef98b8a9f965c7f6dc185a0 (diff) | |
download | ouroboros-5b74bb43d36624c4cfb81d5b37833ea241061b26.tar.gz ouroboros-5b74bb43d36624c4cfb81d5b37833ea241061b26.zip |
Merged in dstaesse/ouroboros/be-irmd-fix (pull request #222)
Fix locks
Diffstat (limited to 'src')
-rw-r--r-- | src/ipcpd/normal/main.c | 7 | ||||
-rw-r--r-- | src/irmd/main.c | 19 |
2 files changed, 18 insertions, 8 deletions
diff --git a/src/ipcpd/normal/main.c b/src/ipcpd/normal/main.c index 9479b806..a067fb83 100644 --- a/src/ipcpd/normal/main.c +++ b/src/ipcpd/normal/main.c @@ -136,14 +136,13 @@ static int normal_ipcp_enroll(char * dif_name) return -1; /* -ENOTINIT */ } + pthread_rwlock_unlock(&_ipcp->state_lock); + if (fmgr_mgmt_flow(dif_name)) { - pthread_rwlock_unlock(&_ipcp->state_lock); LOG_ERR("Failed to establish management flow."); return -1; } - pthread_rwlock_unlock(&_ipcp->state_lock); - if (ipcp_wait_state(_ipcp, IPCP_ENROLLED, &timeout) == -ETIMEDOUT) { LOG_ERR("Enrollment timed out."); return -1; @@ -156,6 +155,8 @@ static int normal_ipcp_enroll(char * dif_name) return -1; } + pthread_rwlock_unlock(&_ipcp->state_lock); + return 0; } 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; } |