diff options
author | Sander Vrijders <sander.vrijders@intec.ugent.be> | 2016-04-23 09:53:35 +0200 |
---|---|---|
committer | Sander Vrijders <sander.vrijders@intec.ugent.be> | 2016-04-23 09:53:35 +0200 |
commit | b6dc5ba9576d61d42db82c3da8cb0c039fac7179 (patch) | |
tree | 0de76147c8a7beb4c23a1931f822113b61c51a5b /src/irmd/main.c | |
parent | 9687ace9a1faf752672774ae49a6428b378fa409 (diff) | |
parent | a618984537f7790cd274d097223b4029473044c2 (diff) | |
download | ouroboros-b6dc5ba9576d61d42db82c3da8cb0c039fac7179.tar.gz ouroboros-b6dc5ba9576d61d42db82c3da8cb0c039fac7179.zip |
Merge remote-tracking branch 'upstream/be' into be
Diffstat (limited to 'src/irmd/main.c')
-rw-r--r-- | src/irmd/main.c | 49 |
1 files changed, 44 insertions, 5 deletions
diff --git a/src/irmd/main.c b/src/irmd/main.c index 1f1c4839..13076cd1 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -22,6 +22,7 @@ #define OUROBOROS_PREFIX "irmd" +#include <ouroboros/config.h> #include <ouroboros/logs.h> #include <ouroboros/common.h> #include <ouroboros/sockets.h> @@ -32,11 +33,14 @@ #include <ouroboros/instance_name.h> #include <ouroboros/utils.h> #include <ouroboros/dif_config.h> +#include <ouroboros/shm_du_map.h> #include <sys/socket.h> #include <sys/un.h> +#include <signal.h> #include <stdlib.h> #include <errno.h> +#include <string.h> struct ipcp_entry { struct list_head next; @@ -50,6 +54,7 @@ struct irm { }; struct irm * instance = NULL; +struct shm_du_map * dum; static pid_t find_pid_by_ipcp_name(instance_name_t * api) { @@ -59,8 +64,6 @@ static pid_t find_pid_by_ipcp_name(instance_name_t * api) struct ipcp_entry * tmp = list_entry(pos, struct ipcp_entry, next); - LOG_DBG("name is %s", api->name); - if (instance_name_cmp(api, tmp->api) == 0) return tmp->pid; } @@ -97,8 +100,9 @@ static int create_ipcp(instance_name_t * api, } tmp = malloc(sizeof(*tmp)); - if (tmp == NULL) + if (tmp == NULL) { return -1; + } INIT_LIST_HEAD(&tmp->next); @@ -330,12 +334,45 @@ static int flow_dealloc_ipcp(uint32_t port_id) return -1; } -/* FIXME: Close sockfd on closing and release irm */ +void irmd_sig_handler(int sig, siginfo_t * info, void * c) +{ + switch(sig) { + case SIGINT: + case SIGTERM: + case SIGHUP: + shm_du_map_close(dum); + free(instance); + exit(0); + default: + return; + } +} + int main() { int sockfd; uint8_t buf[IRM_MSG_BUF_SIZE]; + struct sigaction sig_act; + + /* init sig_act */ + memset (&sig_act, 0, sizeof sig_act); + + /* install signal traps */ + sig_act.sa_sigaction = &irmd_sig_handler; + sig_act.sa_flags = SA_SIGINFO; + + sigaction(SIGINT, &sig_act, NULL); + sigaction(SIGTERM, &sig_act, NULL); + sigaction(SIGHUP, &sig_act, NULL); + + + if (access("/dev/shm/" SHM_DU_MAP_FILENAME, F_OK) != -1) + unlink("/dev/shm/" SHM_DU_MAP_FILENAME); + + if ((dum = shm_du_map_create()) == NULL) + return -1; + instance = malloc(sizeof(*instance)); if (instance == NULL) return -1; @@ -343,8 +380,10 @@ int main() INIT_LIST_HEAD(&instance->ipcps); sockfd = server_socket_open(IRM_SOCK_PATH); - if (sockfd < 0) + if (sockfd < 0) { + free(instance); return -1; + } while (true) { int cli_sockfd; |