summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordimitri staessens <[email protected]>2017-03-20 13:41:32 +0000
committerSander Vrijders <[email protected]>2017-03-20 13:41:32 +0000
commit3bb7ed41f8c96a15f16281f3c9f282e6690aed38 (patch)
tree47253bfd01c7c42677d292cc7d817d830f0a430c /src
parent62e725ced1395b161b0fd66aea433c709850cc57 (diff)
parentd14259796288f9d3eae907408b3c9c2e8c750a9c (diff)
downloadouroboros-3bb7ed41f8c96a15f16281f3c9f282e6690aed38.tar.gz
ouroboros-3bb7ed41f8c96a15f16281f3c9f282e6690aed38.zip
Merged in dstaesse/ouroboros/be-connmgr (pull request #403)
ipcpd: Fix cleanup of connmgr
Diffstat (limited to 'src')
-rw-r--r--src/ipcpd/normal/connmgr.c43
-rw-r--r--src/ipcpd/normal/enroll.c23
-rw-r--r--src/ipcpd/normal/main.c4
3 files changed, 39 insertions, 31 deletions
diff --git a/src/ipcpd/normal/connmgr.c b/src/ipcpd/normal/connmgr.c
index c86beae8..b97d2b23 100644
--- a/src/ipcpd/normal/connmgr.c
+++ b/src/ipcpd/normal/connmgr.c
@@ -192,6 +192,27 @@ void connmgr_stop(void)
pthread_join(connmgr.acceptor, NULL);
}
+static void destroy_ae(struct ae * ae)
+{
+ struct list_head * p = NULL;
+ struct list_head * h = NULL;
+
+ pthread_mutex_lock(&ae->conn_lock);
+
+ list_for_each_safe(p, h, &ae->conn_list) {
+ struct ae_conn * e = list_entry(p, struct ae_conn, next);
+ list_del(&e->next);
+ free(e);
+ }
+
+ pthread_mutex_unlock(&ae->conn_lock);
+
+ pthread_cond_destroy(&ae->conn_cond);
+ pthread_mutex_destroy(&ae->conn_lock);
+
+ free(ae);
+}
+
void connmgr_fini(void)
{
struct list_head * p = NULL;
@@ -201,7 +222,8 @@ void connmgr_fini(void)
list_for_each_safe(p, n, &connmgr.aes) {
struct ae * e = list_entry(p, struct ae, next);
- connmgr_ae_destroy(e);
+ list_del(&e->next);
+ destroy_ae(e);
}
pthread_mutex_unlock(&connmgr.aes_lock);
@@ -242,30 +264,15 @@ struct ae * connmgr_ae_create(struct conn_info info)
void connmgr_ae_destroy(struct ae * ae)
{
- struct list_head * p = NULL;
- struct list_head * n = NULL;
-
assert(ae);
pthread_mutex_lock(&connmgr.aes_lock);
- pthread_mutex_lock(&ae->conn_lock);
-
- list_for_each_safe(p, n, &ae->conn_list) {
- struct ae_conn * e = list_entry(p, struct ae_conn, next);
- list_del(&e->next);
- free(e);
- }
-
- pthread_mutex_unlock(&ae->conn_lock);
-
- pthread_cond_destroy(&ae->conn_cond);
- pthread_mutex_destroy(&ae->conn_lock);
list_del(&ae->next);
- pthread_mutex_unlock(&connmgr.aes_lock);
+ destroy_ae(ae);
- free(ae);
+ pthread_mutex_unlock(&connmgr.aes_lock);
}
int connmgr_alloc(struct ae * ae,
diff --git a/src/ipcpd/normal/enroll.c b/src/ipcpd/normal/enroll.c
index bdf55fe8..7e15be11 100644
--- a/src/ipcpd/normal/enroll.c
+++ b/src/ipcpd/normal/enroll.c
@@ -73,15 +73,15 @@ static void * enroll_handle(void * o)
(void) o;
while (true) {
- if (connmgr_wait(enroll.ae, &conn)) {
- log_err("Failed to get next connection.");
- continue;
- }
-
cdap = cdap_create();
if (cdap == NULL) {
log_err("Failed to instantiate CDAP.");
- flow_dealloc(conn.flow_info.fd);
+ continue;
+ }
+
+ if (connmgr_wait(enroll.ae, &conn)) {
+ log_err("Failed to get next connection.");
+ cdap_destroy(cdap);
continue;
}
@@ -179,17 +179,18 @@ int enroll_boot(char * dst_name)
char * members_ro = MEMBERS_PATH;
char * dif_ro = DIF_PATH;
- if (connmgr_alloc(enroll.ae, dst_name, NULL, &conn)) {
- log_err("Failed to get connection.");
- return -1;
- }
-
cdap = cdap_create();
if (cdap == NULL) {
log_err("Failed to instantiate CDAP.");
return -1;
}
+ if (connmgr_alloc(enroll.ae, dst_name, NULL, &conn)) {
+ log_err("Failed to get connection.");
+ cdap_destroy(cdap);
+ return -1;
+ }
+
if (cdap_add_flow(cdap, conn.flow_info.fd)) {
log_warn("Failed to add flow to CDAP.");
cdap_destroy(cdap);
diff --git a/src/ipcpd/normal/main.c b/src/ipcpd/normal/main.c
index 814a0c0b..398d6ee3 100644
--- a/src/ipcpd/normal/main.c
+++ b/src/ipcpd/normal/main.c
@@ -472,10 +472,10 @@ int main(int argc,
rib_fini();
- connmgr_fini();
-
enroll_fini();
+ connmgr_fini();
+
irm_unbind_api(getpid(), ipcpi.name);
ipcp_fini();