summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@intec.ugent.be>2016-07-06 22:09:15 +0200
committerdimitri staessens <dimitri.staessens@intec.ugent.be>2016-07-06 22:13:35 +0200
commit6f8024ef27933d0123aee3d02002ca3600270e72 (patch)
treefe89505651f156707374cb4b11e2258b19ac8eae
parentf797b763dd9fa95d5294f60232babb017b2b495f (diff)
downloadouroboros-6f8024ef27933d0123aee3d02002ca3600270e72.tar.gz
ouroboros-6f8024ef27933d0123aee3d02002ca3600270e72.zip
lib:irmd: Fix logs and irm_create
The irm_create() function called irmd_destroy before some key values were initialized. Logs cleanup was missing.
-rw-r--r--include/ouroboros/logs.h3
-rw-r--r--src/irmd/main.c28
-rw-r--r--src/lib/logs.c6
3 files changed, 25 insertions, 12 deletions
diff --git a/include/ouroboros/logs.h b/include/ouroboros/logs.h
index 0ffc5699..db3f8519 100644
--- a/include/ouroboros/logs.h
+++ b/include/ouroboros/logs.h
@@ -30,7 +30,8 @@
#error You must define OUROBOROS_PREFIX before including this file
#endif
-int set_logfile(char * filename);
+int set_logfile(char * filename);
+void close_logfile();
#define ANSI_COLOR_RED "\x1b[31m"
#define ANSI_COLOR_GREEN "\x1b[32m"
diff --git a/src/irmd/main.c b/src/irmd/main.c
index 26251858..62673251 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -1696,6 +1696,8 @@ 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();
@@ -1716,6 +1718,8 @@ static struct irm * irm_create()
free(instance);
exit(EXIT_SUCCESS);
}
+
+ 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;
@@ -1894,5 +1898,7 @@ int main(int argc, char ** argv)
irm_destroy();
+ close_logfile();
+
exit(EXIT_SUCCESS);
}
diff --git a/src/lib/logs.c b/src/lib/logs.c
index d86073e4..eed1ee10 100644
--- a/src/lib/logs.c
+++ b/src/lib/logs.c
@@ -34,3 +34,9 @@ int set_logfile(char * filename)
return 0;
}
+
+void close_logfile()
+{
+ if (logfile != NULL)
+ fclose(logfile);
+}