diff options
author | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-06-20 21:58:17 +0200 |
---|---|---|
committer | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-06-20 21:58:17 +0200 |
commit | 34f96731f5fb8ab8a1f7018366fc28fd041d73e2 (patch) | |
tree | aff0b0ed3474c7cdb5f6ba7e62ca5e33ccedb814 /src/irmd/main.c | |
parent | 6270143e57306d11be5c02ee3c7857808583c0f5 (diff) | |
parent | 550cfa775b048abe183c4fdcc8ada8476e562185 (diff) | |
download | ouroboros-34f96731f5fb8ab8a1f7018366fc28fd041d73e2.tar.gz ouroboros-34f96731f5fb8ab8a1f7018366fc28fd041d73e2.zip |
Merged in sandervrijders/ouroboros/be (pull request #134)
build: Change install directories and set correct permissions
Diffstat (limited to 'src/irmd/main.c')
-rw-r--r-- | src/irmd/main.c | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/irmd/main.c b/src/irmd/main.c index 7ad7a23a..5f7c1ddc 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -49,6 +49,7 @@ #include <string.h> #include <limits.h> #include <pthread.h> +#include <sys/stat.h> #ifndef IRMD_MAX_FLOWS #define IRMD_MAX_FLOWS 4096 @@ -1571,16 +1572,20 @@ void * mainloop() static struct irm * irm_create() { + struct stat st = {0}; + struct irm * i = malloc(sizeof(*i)); if (i == NULL) return 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."); exit(EXIT_FAILURE); } + if (kill(shm_du_map_owner(dum), 0) < 0) { LOG_INFO("IRMd didn't properly shut down last time."); shm_du_map_destroy(dum); @@ -1592,6 +1597,11 @@ static struct irm * irm_create() } } + if (rw_lock_init(&i->state_lock)) { + irm_destroy(i); + return NULL; + } + i->threadpool = malloc(sizeof(pthread_t) * IRMD_THREADPOOL_SIZE); if (i->threadpool == NULL) { irm_destroy(i); @@ -1613,13 +1623,22 @@ static struct irm * irm_create() return NULL; } + if (stat(SOCK_PATH, &st) == -1) { + if (mkdir(SOCK_PATH, 0777)) { + LOG_ERR("Failed to create sockets directory."); + irm_destroy(i); + return NULL; + } + } + i->sockfd = server_socket_open(IRM_SOCK_PATH); if (i->sockfd < 0) { irm_destroy(i); return NULL; } - if (rw_lock_init(&i->state_lock)) { + if (chmod(IRM_SOCK_PATH, 0666)) { + LOG_ERR("Failed to chmod socket."); irm_destroy(i); return NULL; } @@ -1643,6 +1662,11 @@ int main() int t = 0; + if (geteuid() != 0) { + LOG_ERR("IPC Resource Manager must be run as root."); + exit(EXIT_FAILURE); + } + /* init sig_act */ memset(&sig_act, 0, sizeof sig_act); @@ -1661,7 +1685,7 @@ int main() instance = irm_create(); if (instance == NULL) - return 1; + exit(EXIT_FAILURE); pthread_create(&instance->cleanup_flows, NULL, irm_flow_cleaner, NULL); |