summaryrefslogtreecommitdiff
path: root/src/irmd/main.c
diff options
context:
space:
mode:
authorSander Vrijders <[email protected]>2016-07-02 19:15:26 +0200
committerSander Vrijders <[email protected]>2016-07-02 19:15:26 +0200
commitde63f8b37f82ef6a760c7d3dafe2251160e2c114 (patch)
treecd79dba391c0ded80125836069d8187a22f7e5f5 /src/irmd/main.c
parentcd4d09aae14afe7b0aa0890c61b0ad43e4f23b28 (diff)
parent79475a4742bc28e1737044f2300bcb601e6e10bf (diff)
downloadouroboros-de63f8b37f82ef6a760c7d3dafe2251160e2c114.tar.gz
ouroboros-de63f8b37f82ef6a760c7d3dafe2251160e2c114.zip
Merged in dstaesse/ouroboros/be-shm-robust (pull request #147)
lib: robust locking in shared memory and crash recovery
Diffstat (limited to 'src/irmd/main.c')
-rw-r--r--src/irmd/main.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/irmd/main.c b/src/irmd/main.c
index 5ff84da1..b4771b89 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -30,6 +30,7 @@
#include <ouroboros/list.h>
#include <ouroboros/utils.h>
#include <ouroboros/irm_config.h>
+#include <ouroboros/shm_ap_rbuff.h>
#include <ouroboros/shm_du_map.h>
#include <ouroboros/bitmap.h>
#include <ouroboros/flow.h>
@@ -163,7 +164,7 @@ static void reg_instance_destroy(struct reg_instance * i)
while (wait) {
pthread_mutex_lock(&i->mutex);
- if (pthread_cond_destroy(&i->wakeup) < 0)
+ if (pthread_cond_destroy(&i->wakeup))
pthread_cond_broadcast(&i->wakeup);
else
wait = false;
@@ -291,7 +292,7 @@ static void port_map_entry_destroy(struct port_map_entry * e)
while (wait) {
pthread_mutex_lock(&e->res_lock);
- if (pthread_cond_destroy(&e->res_signal) < 0)
+ if (pthread_cond_destroy(&e->res_signal))
pthread_cond_broadcast(&e->res_signal);
else
wait = false;
@@ -477,7 +478,7 @@ static void reg_entry_destroy(struct reg_entry * e)
while (wait) {
pthread_mutex_lock(&e->state_lock);
- if (pthread_cond_destroy(&e->acc_signal) < 0)
+ if (pthread_cond_destroy(&e->acc_signal))
pthread_cond_broadcast(&e->acc_signal);
else
wait = false;
@@ -1942,18 +1943,26 @@ void * irm_flow_cleaner()
pthread_mutex_unlock(&e->res_lock);
if (kill(e->n_api, 0) < 0) {
+ struct shm_ap_rbuff * n_rb =
+ shm_ap_rbuff_open(e->n_api);
bmp_release(instance->port_ids, e->port_id);
list_del(&e->next);
LOG_INFO("Process %d gone, %d deallocated.",
e->n_api, e->port_id);
ipcp_flow_dealloc(e->n_1_api, e->port_id);
+ if (n_rb != NULL)
+ shm_ap_rbuff_destroy(n_rb);
port_map_entry_destroy(e);
}
if (kill(e->n_1_api, 0) < 0) {
+ struct shm_ap_rbuff * n_1_rb =
+ shm_ap_rbuff_open(e->n_1_api);
list_del(&e->next);
LOG_ERR("IPCP %d gone, flow %d removed.",
e->n_1_api, e->port_id);
+ if (n_1_rb != NULL)
+ shm_ap_rbuff_destroy(n_1_rb);
port_map_entry_destroy(e);
}
}
@@ -2205,7 +2214,8 @@ static struct irm * irm_create()
shm_du_map_destroy(dum);
LOG_INFO("Stale shm file removed.");
} else {
- LOG_INFO("IRMd already running, exiting.");
+ LOG_INFO("IRMd already running (%d), exiting.",
+ shm_du_map_owner(dum));
free(instance);
exit(EXIT_SUCCESS);
}