summaryrefslogtreecommitdiff
path: root/src/irmd
diff options
context:
space:
mode:
authorSander Vrijders <[email protected]>2016-07-07 09:50:30 +0200
committerSander Vrijders <[email protected]>2016-07-07 09:50:30 +0200
commit80441117cf61137c6a8c97e0779e70d76ae8541d (patch)
tree01691cd4b34c9a5292f375dd1d12e80335dfeaf8 /src/irmd
parentb61b1ce112261f812ff1d6093b89768eeca237b5 (diff)
parent442c2b866e55545a0e21eaaf36b11621c8110411 (diff)
downloadouroboros-80441117cf61137c6a8c97e0779e70d76ae8541d.tar.gz
ouroboros-80441117cf61137c6a8c97e0779e70d76ae8541d.zip
Merged in dstaesse/ouroboros/be-irmd-fix-create (pull request #164)
lib:irmd: Fix logs and irm_create
Diffstat (limited to 'src/irmd')
-rw-r--r--src/irmd/main.c36
1 files changed, 22 insertions, 14 deletions
diff --git a/src/irmd/main.c b/src/irmd/main.c
index 26251858..1f72fa1a 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -1696,13 +1696,15 @@ static struct irm * irm_create()
if (instance == NULL)
return NULL;
+ instance->state = IRMD_NULL;
+
if (access("/dev/shm/" SHM_DU_MAP_FILENAME, F_OK) != -1) {
struct shm_du_map * dum = shm_du_map_open();
if (dum == NULL) {
LOG_ERR("Could not examine existing shm file.");
free(instance);
- exit(EXIT_FAILURE);
+ return NULL;
}
if (kill(shm_du_map_owner(dum), 0) < 0) {
@@ -1714,8 +1716,10 @@ static struct irm * irm_create()
shm_du_map_owner(dum));
shm_du_map_close(dum);
free(instance);
- exit(EXIT_SUCCESS);
+ return NULL;
}
+
+ shm_du_map_close(dum);
}
if (pthread_rwlock_init(&instance->state_lock, NULL)) {
@@ -1736,17 +1740,6 @@ static struct irm * irm_create()
return NULL;
}
- instance->threadpool = malloc(sizeof(pthread_t) * IRMD_THREADPOOL_SIZE);
- if (instance->threadpool == NULL) {
- irm_destroy();
- return NULL;
- }
-
- if ((instance->dum = shm_du_map_create()) == NULL) {
- irm_destroy();
- return NULL;
- }
-
INIT_LIST_HEAD(&instance->ipcps);
INIT_LIST_HEAD(&instance->spawned_apis);
INIT_LIST_HEAD(&instance->registry);
@@ -1758,6 +1751,12 @@ static struct irm * irm_create()
return NULL;
}
+ instance->threadpool = malloc(sizeof(pthread_t) * IRMD_THREADPOOL_SIZE);
+ if (instance->threadpool == NULL) {
+ irm_destroy();
+ return NULL;
+ }
+
if (stat(SOCK_PATH, &st) == -1) {
if (mkdir(SOCK_PATH, 0777)) {
LOG_ERR("Failed to create sockets directory.");
@@ -1778,6 +1777,11 @@ static struct irm * irm_create()
return NULL;
}
+ if ((instance->dum = shm_du_map_create()) == NULL) {
+ irm_destroy();
+ return NULL;
+ }
+
instance->state = IRMD_RUNNING;
return instance;
@@ -1875,8 +1879,10 @@ int main(int argc, char ** argv)
exit(EXIT_FAILURE);
instance = irm_create();
- if (instance == NULL)
+ if (instance == NULL) {
+ close_logfile();
exit(EXIT_FAILURE);
+ }
for (t = 0; t < IRMD_THREADPOOL_SIZE; ++t)
pthread_create(&instance->threadpool[t], NULL, mainloop, NULL);
@@ -1894,5 +1900,7 @@ int main(int argc, char ** argv)
irm_destroy();
+ close_logfile();
+
exit(EXIT_SUCCESS);
}