diff options
author | dimitri staessens <[email protected]> | 2017-03-22 16:06:52 +0000 |
---|---|---|
committer | Sander Vrijders <[email protected]> | 2017-03-22 16:06:52 +0000 |
commit | 4d31a76040e3bc9218cd731f745c9ea4e38a2a5a (patch) | |
tree | 9fd26561be8e27f15d69129f6f7257a136888eb5 /src | |
parent | 79090eb2fc0fe4f6582aca556c05435dace60046 (diff) | |
parent | 3964be811b57fca965b979b7c21f24532a172bd4 (diff) | |
download | ouroboros-4d31a76040e3bc9218cd731f745c9ea4e38a2a5a.tar.gz ouroboros-4d31a76040e3bc9218cd731f745c9ea4e38a2a5a.zip |
Merged in dstaesse/ouroboros/be-fixes (pull request #413)
Be fixes
Diffstat (limited to 'src')
-rw-r--r-- | src/ipcpd/normal/connmgr.c | 6 | ||||
-rw-r--r-- | src/ipcpd/normal/enroll.c | 32 |
2 files changed, 22 insertions, 16 deletions
diff --git a/src/ipcpd/normal/connmgr.c b/src/ipcpd/normal/connmgr.c index b97d2b23..b8314917 100644 --- a/src/ipcpd/normal/connmgr.c +++ b/src/ipcpd/normal/connmgr.c @@ -328,7 +328,7 @@ int connmgr_alloc(struct ae * ae, int connmgr_wait(struct ae * ae, struct conn * conn) { - struct ae_conn * ae_conn; + struct ae_conn * ae_conn = NULL; assert(ae); assert(conn); @@ -341,6 +341,8 @@ int connmgr_wait(struct ae * ae, while (list_is_empty(&ae->conn_list)) pthread_cond_wait(&ae->conn_cond, &ae->conn_lock); + pthread_cleanup_pop(false); + ae_conn = list_first_entry((&ae->conn_list), struct ae_conn, next); if (ae_conn == NULL) { pthread_mutex_unlock(&ae->conn_lock); @@ -352,7 +354,7 @@ int connmgr_wait(struct ae * ae, list_del(&ae_conn->next); free(ae_conn); - pthread_cleanup_pop(true); + pthread_mutex_unlock(&ae->conn_lock); return 0; } diff --git a/src/ipcpd/normal/enroll.c b/src/ipcpd/normal/enroll.c index 7e15be11..0b0db1cf 100644 --- a/src/ipcpd/normal/enroll.c +++ b/src/ipcpd/normal/enroll.c @@ -46,8 +46,9 @@ #define ENROLL_WARN_TIME_OFFSET 20 struct { - struct ae * ae; - pthread_t listener; + struct ae * ae; + struct cdap * cdap; + pthread_t listener; } enroll; static void * enroll_handle(void * o) @@ -70,24 +71,18 @@ static void * enroll_handle(void * o) char * members_ro = MEMBERS_PATH; char * dif_ro = DIF_PATH; - (void) o; + cdap = (struct cdap *) o; - while (true) { - cdap = cdap_create(); - if (cdap == NULL) { - log_err("Failed to instantiate CDAP."); - continue; - } + assert(cdap); + while (true) { if (connmgr_wait(enroll.ae, &conn)) { log_err("Failed to get next connection."); - cdap_destroy(cdap); continue; } if (cdap_add_flow(cdap, conn.flow_info.fd)) { log_warn("Failed to add flow to CDAP."); - cdap_destroy(cdap); flow_dealloc(conn.flow_info.fd); continue; } @@ -155,7 +150,7 @@ static void * enroll_handle(void * o) log_dbg("Sent boot info to new member."); - cdap_destroy(cdap); + cdap_del_flow(cdap, conn.flow_info.fd); flow_dealloc(conn.flow_info.fd); } @@ -337,6 +332,12 @@ int enroll_init(void) { struct conn_info info; + enroll.cdap = cdap_create(); + if (enroll.cdap == NULL) { + log_err("Failed to instantiate CDAP."); + return -1; + } + memset(&info, 0, sizeof(info)); strcpy(info.ae_name, ENROLL_AE); @@ -345,20 +346,23 @@ int enroll_init(void) info.pref_syntax = PROTO_GPB; enroll.ae = connmgr_ae_create(info); - if (enroll.ae == NULL) + if (enroll.ae == NULL) { + cdap_destroy(enroll.cdap); return -1; + } return 0; } void enroll_fini(void) { + cdap_destroy(enroll.cdap); connmgr_ae_destroy(enroll.ae); } int enroll_start(void) { - if (pthread_create(&enroll.listener, NULL, enroll_handle, NULL)) + if (pthread_create(&enroll.listener, NULL, enroll_handle, enroll.cdap)) return -1; return 0; |