From 21b304b46a347772c1338b22fba6a15291bb2945 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Sun, 17 Apr 2016 12:08:49 +0200 Subject: ipcpd: initial IPC processes Basic functions for implementation of IPC processes, and implementation of core functions of the shim IPCP over UDP. Updates to the build system to compile these IPC processes, as well as some fixes in the irmd (rudimentary capturing exit signals) and some fixes in the library, mainly relating to the messaging. Basic implementation of creation / bootstrapping / deletion of the shim UDP. Placeholders for other functions. --- src/irmd/main.c | 49 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) (limited to 'src/irmd') 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 #include #include #include @@ -32,11 +33,14 @@ #include #include #include +#include #include #include +#include #include #include +#include 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; -- cgit v1.2.3