diff options
-rw-r--r-- | include/ouroboros/irm_config.h | 1 | ||||
-rw-r--r-- | src/ipcpd/ipcp.c | 16 | ||||
-rw-r--r-- | src/irmd/apn_table.c | 17 | ||||
-rw-r--r-- | src/irmd/apn_table.h | 3 | ||||
-rw-r--r-- | src/irmd/main.c | 16 | ||||
-rw-r--r-- | src/tools/irm/irm_bind_ap.c | 2 | ||||
-rw-r--r-- | src/tools/irm/irm_ipcp_bootstrap.c | 5 | ||||
-rw-r--r-- | src/tools/irm/irm_ipcp_enroll.c | 5 |
8 files changed, 50 insertions, 15 deletions
diff --git a/include/ouroboros/irm_config.h b/include/ouroboros/irm_config.h index f90ad927..d5f2b565 100644 --- a/include/ouroboros/irm_config.h +++ b/include/ouroboros/irm_config.h @@ -30,7 +30,6 @@ #define BIND_AP_AUTO 0x01 #define BIND_AP_UNIQUE 0x02 -#define BIND_AP_LOC 0x04 enum ipcp_type { IPCP_NORMAL = 0, diff --git a/src/ipcpd/ipcp.c b/src/ipcpd/ipcp.c index cc77af89..1c4fab94 100644 --- a/src/ipcpd/ipcp.c +++ b/src/ipcpd/ipcp.c @@ -103,7 +103,13 @@ int ipcp_parse_arg(int argc, char * argv[]) static void close_ptr(void * o) { + char * name = ipcp_sock_path(getpid()); close(*((int *) o)); + + if (unlink(name)) + LOG_DBG("Could not unlink %s.", name); + + free(name); } static void clean_msg(void * msg) @@ -127,6 +133,7 @@ void * ipcp_main_loop(void * o) struct dif_config conf; char * sock_path; + char * msg_name_dup; struct timeval tv = {(SOCKET_TIMEOUT / 1000), (SOCKET_TIMEOUT % 1000) * 1000}; @@ -188,7 +195,7 @@ void * ipcp_main_loop(void * o) } conf_msg = msg->conf; conf.type = conf_msg->ipcp_type; - conf.dif_name = conf_msg->dif_name; + conf.dif_name = strdup(conf_msg->dif_name); if (conf.dif_name == NULL) { ret_msg.has_result = true; ret_msg.result = -1; @@ -217,6 +224,8 @@ void * ipcp_main_loop(void * o) ret_msg.has_result = true; ret_msg.result = _ipcp->ops->ipcp_bootstrap(&conf); + if (ret_msg.result < 0) + free(conf.dif_name); break; case IPCP_MSG_CODE__IPCP_ENROLL: if (_ipcp->ops->ipcp_enroll == NULL) { @@ -232,9 +241,12 @@ void * ipcp_main_loop(void * o) LOG_ERR("Ap_reg unsupported."); break; } + msg_name_dup = strdup(msg->name); ret_msg.has_result = true; ret_msg.result = - _ipcp->ops->ipcp_name_reg(strdup(msg->name)); + _ipcp->ops->ipcp_name_reg(msg_name_dup); + if (ret_msg.result < 0) + free(msg_name_dup); break; case IPCP_MSG_CODE__IPCP_NAME_UNREG: if (_ipcp->ops->ipcp_name_unreg == NULL) { diff --git a/src/irmd/apn_table.c b/src/irmd/apn_table.c index 31c45a78..a7cf0fd3 100644 --- a/src/irmd/apn_table.c +++ b/src/irmd/apn_table.c @@ -162,3 +162,20 @@ struct apn_entry * apn_table_get(struct list_head * apn_table, char * ap) return NULL; } + +struct apn_entry * apn_table_get_by_apn(struct list_head * apn_table, + char * apn) +{ + struct list_head * p; + + if (apn_table == NULL || apn == NULL) + return NULL; + + list_for_each(p, apn_table) { + struct apn_entry * e = list_entry(p, struct apn_entry, next); + if (!strcmp(e->apn, apn)) + return e; + } + + return NULL; +} diff --git a/src/irmd/apn_table.h b/src/irmd/apn_table.h index 88a2548a..fd0fb1de 100644 --- a/src/irmd/apn_table.h +++ b/src/irmd/apn_table.h @@ -59,4 +59,7 @@ void apn_table_del(struct list_head * apn_table, struct apn_entry * apn_table_get(struct list_head * apn_table, char * ap); +struct apn_entry * apn_table_get_by_apn(struct list_head * apn_table, + char * apn); + #endif /* OUROBOROS_IRMD_APN_TABLE_H */ diff --git a/src/irmd/main.c b/src/irmd/main.c index 06cf0e07..8ac645df 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -1286,15 +1286,16 @@ static pid_t auto_execute(char ** argv) return -1; } - LOG_INFO("Executing %s.", argv[0]); api = fork(); if (api == -1) { LOG_ERR("Failed to fork"); return api; } - if (api != 0) + if (api != 0) { + LOG_INFO("Instantiated %s as AP-i %d.", argv[0], api); return api; + } execv(argv[0], argv); @@ -1363,7 +1364,8 @@ static struct irm_flow * flow_req_arr(pid_t api, pthread_mutex_lock(&re->state_lock); re->state = REG_NAME_AUTO_EXEC; - a = apn_table_get(&irmd->apn_table, reg_entry_get_apn(re)); + a = apn_table_get_by_apn(&irmd->apn_table, + reg_entry_get_apn(re)); pthread_mutex_unlock(&re->state_lock); if (a == NULL || (c_api->pid = auto_execute(a->argv)) < 0) { pthread_mutex_lock(&re->state_lock); @@ -1595,6 +1597,9 @@ static void irm_destroy() close(irmd->sockfd); + if (unlink(IRM_SOCK_PATH)) + LOG_DBG("Failed to unlink %s.", IRM_SOCK_PATH); + pthread_rwlock_unlock(&irmd->state_lock); pthread_rwlock_destroy(&irmd->reg_lock); @@ -1650,9 +1655,9 @@ void * irm_sanitize() list_for_each_safe(p, h, &irmd->spawned_apis) { struct pid_el * e = list_entry(p, struct pid_el, next); + waitpid(e->pid, &s, WNOHANG); if (kill(e->pid, 0) >= 0) continue; - waitpid(e->pid, &s, WNOHANG); LOG_DBG("Child process %d died, error %d.", e->pid, s); list_del(&e->next); free(e); @@ -1690,8 +1695,7 @@ void * irm_sanitize() continue; LOG_DBG("Dead AP-I removed from: %d %s.", a->pid, e->name); - list_del(&a->next); - free(a); + reg_entry_del_api(e, a->pid); } } diff --git a/src/tools/irm/irm_bind_ap.c b/src/tools/irm/irm_bind_ap.c index a525c077..189b197e 100644 --- a/src/tools/irm/irm_bind_ap.c +++ b/src/tools/irm/irm_bind_ap.c @@ -61,8 +61,6 @@ int do_bind_ap(int argc, char ** argv) flags |= BIND_AP_AUTO; } else if (strcmp(*argv, "unique") == 0) { flags |= BIND_AP_UNIQUE; - } else if (strcmp(*argv, "loc") == 0) { - flags |= BIND_AP_LOC; } else if (strcmp(*argv, "--") == 0) { ++argv; --argc; diff --git a/src/tools/irm/irm_ipcp_bootstrap.c b/src/tools/irm/irm_ipcp_bootstrap.c index 34c5d223..3db43e6e 100644 --- a/src/tools/irm/irm_ipcp_bootstrap.c +++ b/src/tools/irm/irm_ipcp_bootstrap.c @@ -95,7 +95,7 @@ int do_bootstrap_ipcp(int argc, char ** argv) char * ipcp_type = NULL; char * dif_name = NULL; char * if_name = NULL; - pid_t * apis; + pid_t * apis = NULL; ssize_t len = 0; int i = 0; @@ -194,7 +194,8 @@ int do_bootstrap_ipcp(int argc, char ** argv) if (irm_bootstrap_ipcp(apis[i], &conf)) return -1; - free(apis); + if (apis != NULL) + free(apis); return 0; } diff --git a/src/tools/irm/irm_ipcp_enroll.c b/src/tools/irm/irm_ipcp_enroll.c index b7a12e2c..3755f199 100644 --- a/src/tools/irm/irm_ipcp_enroll.c +++ b/src/tools/irm/irm_ipcp_enroll.c @@ -39,7 +39,7 @@ int do_enroll_ipcp(int argc, char ** argv) { char * name = NULL; char * dif_name = NULL; - pid_t * apis; + pid_t * apis = NULL; ssize_t len = 0; int i = 0; @@ -74,7 +74,8 @@ int do_enroll_ipcp(int argc, char ** argv) if (irm_enroll_ipcp(apis[i], dif_name)) return -1; - free(apis); + if (apis != NULL) + free(apis); return 0; } |