summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@ugent.be>2017-03-25 11:06:25 +0000
committerSander Vrijders <sander.vrijders@ugent.be>2017-03-25 11:06:25 +0000
commit1d9061666656ba1cc5a5c72fcc564a3a45b2dd8a (patch)
tree8f46da795657fc2e461c61ec3f4180e32fd68151 /src
parent9cf1bc3d88334249092cb30eb9c789d870e6768b (diff)
parent006da084997e7a27eac5f037356e269fedac00bb (diff)
downloadouroboros-1d9061666656ba1cc5a5c72fcc564a3a45b2dd8a.tar.gz
ouroboros-1d9061666656ba1cc5a5c72fcc564a3a45b2dd8a.zip
Merged in dstaesse/ouroboros/be-cdap (pull request #423)
lib: Fix invoke_ids and failure handling in CDAP
Diffstat (limited to 'src')
-rw-r--r--src/ipcpd/normal/ribmgr.c23
-rw-r--r--src/lib/cdap.c59
2 files changed, 30 insertions, 52 deletions
diff --git a/src/ipcpd/normal/ribmgr.c b/src/ipcpd/normal/ribmgr.c
index 2696026a..772269ae 100644
--- a/src/ipcpd/normal/ribmgr.c
+++ b/src/ipcpd/normal/ribmgr.c
@@ -168,6 +168,7 @@ static void * reader(void * o)
break;
case -EFAULT:
log_warn("Hash mismatch, not in sync.");
+ free(data);
break;
default:
log_warn("Error unpacking %s.", name);
@@ -194,6 +195,7 @@ static void * reader(void * o)
break;
case -EFAULT:
log_warn("Hash mismatch, not yet in sync.");
+ free(data);
break;
default:
log_warn("Error unpacking %s.", name);
@@ -223,7 +225,6 @@ static void * reader(void * o)
log_err("Failed to send CDAP reply.");
continue;
}
-
break;
case CDAP_START:
case CDAP_STOP:
@@ -343,18 +344,9 @@ int ribmgr_init(void)
return -1;
}
- ribmgr.gam = gam_create(pg, ribmgr.nbs, ribmgr.ae);
- if (ribmgr.gam == NULL) {
- log_err("Failed to create gam.");
- connmgr_ae_destroy(ribmgr.ae);
- nbs_destroy(ribmgr.nbs);
- return -1;
- }
-
ribmgr.cdap = cdap_create();
if (ribmgr.cdap == NULL) {
log_err("Failed to create CDAP instance.");
- gam_destroy(ribmgr.gam);
connmgr_ae_destroy(ribmgr.ae);
nbs_destroy(ribmgr.nbs);
return -1;
@@ -364,7 +356,16 @@ int ribmgr_init(void)
if (nbs_reg_notifier(ribmgr.nbs, &ribmgr.nb_notifier)) {
log_err("Failed to register notifier.");
cdap_destroy(ribmgr.cdap);
- gam_destroy(ribmgr.gam);
+ connmgr_ae_destroy(ribmgr.ae);
+ nbs_destroy(ribmgr.nbs);
+ return -1;
+ }
+
+ ribmgr.gam = gam_create(pg, ribmgr.nbs, ribmgr.ae);
+ if (ribmgr.gam == NULL) {
+ log_err("Failed to create gam.");
+ nbs_unreg_notifier(ribmgr.nbs, &ribmgr.nb_notifier);
+ cdap_destroy(ribmgr.cdap);
connmgr_ae_destroy(ribmgr.ae);
nbs_destroy(ribmgr.nbs);
return -1;
diff --git a/src/lib/cdap.c b/src/lib/cdap.c
index 524983c2..a60bf8f9 100644
--- a/src/lib/cdap.c
+++ b/src/lib/cdap.c
@@ -300,6 +300,7 @@ static void * sdu_reader(void * o)
rcvd->data = malloc(rcvd->len);
if (rcvd->data == NULL) {
cdap__free_unpacked(msg, NULL);
+ free(rcvd->name);
free(rcvd);
continue;
}
@@ -339,8 +340,8 @@ static void * sdu_reader(void * o)
}
cdap__free_unpacked(msg, NULL);
-
}
+
return (void *) 0;
}
@@ -631,16 +632,7 @@ cdap_key_t * cdap_request_send(struct cdap * instance,
iid = next_invoke_id(instance);
if (iid == INVALID_INVOKE_ID) {
pthread_rwlock_unlock(&instance->flows_lock);
- while(key > keys) {
- struct cdap_req * r =
- cdap_sent_get_by_key(instance,
- *(--key));
- cdap_sent_del(instance, r);
- cdap_req_destroy(r);
- }
-
- free(keys);
- return NULL;
+ return keys;
}
msg.invoke_id = iid;
@@ -652,39 +644,21 @@ cdap_key_t * cdap_request_send(struct cdap * instance,
req = cdap_sent_add(instance, e->fd, *key);
if (req == NULL) {
pthread_rwlock_unlock(&instance->flows_lock);
- while(key > keys) {
- struct cdap_req * r =
- cdap_sent_get_by_key(instance,
- *(--key));
- cdap_sent_del(instance, r);
- release_invoke_id(instance,
- key_to_invoke_id(r->key));
- cdap_req_destroy(r);
- }
release_invoke_id(instance, iid);
- free(keys);
- return NULL;
+ return keys;
}
ret = write_msg(e->fd, &msg);
if (ret == -ENOMEM) {
pthread_rwlock_unlock(&instance->flows_lock);
- while(key >= keys) {
- struct cdap_req * r =
- cdap_sent_get_by_key(instance, *key);
- cdap_sent_del(instance, r);
- release_invoke_id(instance,
- key_to_invoke_id(r->key));
- cdap_req_destroy(r);
- }
-
- free(keys);
- return NULL;
+ cdap_sent_del(instance, req);
+ release_invoke_id(instance, iid);
+ return keys;
}
if (ret < 0) {
- release_invoke_id(instance, iid);
cdap_sent_del(instance, req);
+ release_invoke_id(instance, iid);
}
++key;
@@ -704,7 +678,8 @@ int cdap_reply_wait(struct cdap * instance,
struct cdap_req * r;
invoke_id_t iid = key_to_invoke_id(key);
- if (instance == NULL || iid == INVALID_INVOKE_ID)
+ if (instance == NULL || iid == INVALID_INVOKE_ID
+ || (data != NULL && len == NULL))
return -EINVAL;
r = cdap_sent_get_by_key(instance, key);
@@ -712,11 +687,11 @@ int cdap_reply_wait(struct cdap * instance,
return -EINVAL;
ret = cdap_req_wait(r);
- if (ret < 0)
+ if (ret < 0) {
+ cdap_sent_del(instance, r);
+ release_invoke_id(instance, iid);
return ret;
-
- if (r->response)
- return r->response;
+ }
assert(ret == 0);
@@ -725,11 +700,12 @@ int cdap_reply_wait(struct cdap * instance,
*len = r->data.len;
}
- cdap_sent_del(instance, r);
+ ret = r->response;
+ cdap_sent_del(instance, r);
release_invoke_id(instance, iid);
- return 0;
+ return ret;
}
cdap_key_t cdap_request_wait(struct cdap * instance,
@@ -764,6 +740,7 @@ cdap_key_t cdap_request_wait(struct cdap * instance,
*flags = rcvd->flags;
rcvd->name = NULL;
+ rcvd->data = NULL;
return invoke_id_to_key(rcvd->iid);
}