From bd7a8ea8a1adbd6763aea857e72623929b7ad7a4 Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Tue, 15 Mar 2016 15:43:17 +0100 Subject: irmd, lib: Create and destroy IPC Processes This adds the functionality to create and destroy IPCPs. Upon creation a new process is forked and execve'd. Upon destruction the IPCP is destroyed by killing it with SIGTERM. --- src/irmd/main.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'src/irmd/main.c') diff --git a/src/irmd/main.c b/src/irmd/main.c index 9a072382..b695519a 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -38,7 +38,7 @@ struct name_to_pid_entry { struct list_head next; - int pid; + pid_t pid; rina_name_t * name; }; @@ -46,8 +46,8 @@ struct irm { struct list_head name_to_pid; }; -static int find_pid_by_name(struct irm * instance, - rina_name_t * name) +static pid_t find_pid_by_name(struct irm * instance, + rina_name_t * name) { struct list_head * pos; @@ -68,11 +68,11 @@ static void create_ipcp(struct irm * instance, rina_name_t name, char * ipcp_type) { - int pid; + pid_t pid; struct name_to_pid_entry * tmp; pid = ipcp_create(name, ipcp_type); - if (pid == 0) { + if (pid == -1) { LOG_ERR("Failed to create IPCP"); return; } @@ -90,14 +90,17 @@ static void create_ipcp(struct irm * instance, return; } + LOG_DBG("Created IPC process with pid %d", pid); + list_add(&tmp->next, &instance->name_to_pid); } static void destroy_ipcp(struct irm * instance, rina_name_t name) { - int pid = 0; + pid_t pid = 0; struct list_head * pos; + struct list_head * n; pid = find_pid_by_name(instance, &name); if (pid == 0) { @@ -105,10 +108,12 @@ static void destroy_ipcp(struct irm * instance, return; } + LOG_DBG("Destroying ipcp with pid %d", pid); + if (ipcp_destroy(pid)) LOG_ERR("Could not destroy IPCP"); - list_for_each(pos, &instance->name_to_pid) { + list_for_each_safe(pos, n, &(instance->name_to_pid)) { struct name_to_pid_entry * tmp = list_entry(pos, struct name_to_pid_entry, next); @@ -121,7 +126,7 @@ static void bootstrap_ipcp(struct irm * instance, rina_name_t name, struct dif_config conf) { - int pid = 0; + pid_t pid = 0; pid = find_pid_by_name(instance, &name); if (pid == 0) { @@ -137,7 +142,7 @@ static void enroll_ipcp(struct irm * instance, rina_name_t name, char * dif_name) { - int pid = 0; + pid_t pid = 0; rina_name_t * member; char ** n_1_difs = NULL; ssize_t n_1_difs_size = 0; @@ -166,7 +171,7 @@ static void reg_ipcp(struct irm * instance, char ** difs, size_t difs_size) { - int pid = 0; + pid_t pid = 0; pid = find_pid_by_name(instance, &name); if (pid == 0) { @@ -183,7 +188,7 @@ static void unreg_ipcp(struct irm * instance, char ** difs, size_t difs_size) { - int pid = 0; + pid_t pid = 0; pid = find_pid_by_name(instance, &name); if (pid == 0) { -- cgit v1.2.3