From bfb86b66c8e7d9d8dc45d9075a4db6d10931dccf Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Tue, 7 Feb 2017 20:45:14 +0100 Subject: ipcpd: Refactor ipcpi struct The ipcp-ops header was removed and merged into ipcp.h. The common components dif_name and ipcp_type have been moved to the main ipcp struct. After this move, ipcp_data only contained shim information, so it was renamed to shim_data. The ipcp_init() function checks the type and will only include the shim_data if the type is not an IPCP_NORMAL. All ipcps have been adapted to this change in API. --- src/ipcpd/ipcp.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'src/ipcpd/ipcp.c') diff --git a/src/ipcpd/ipcp.c b/src/ipcpd/ipcp.c index fe87fbd9..53213c39 100644 --- a/src/ipcpd/ipcp.c +++ b/src/ipcpd/ipcp.c @@ -270,15 +270,17 @@ static void * ipcp_main_loop(void * o) return (void *) 0; } -int ipcp_init(enum ipcp_type type, struct ipcp_ops * ops) +int ipcp_init(enum ipcp_type type, + struct ipcp_ops * ops) { pthread_condattr_t cattr; struct timeval tv = {(IPCP_ACCEPT_TIMEOUT / 1000), (IPCP_ACCEPT_TIMEOUT % 1000) * 1000}; - ipcpi.irmd_fd = -1; - ipcpi.state = IPCP_NULL; + ipcpi.irmd_fd = -1; + ipcpi.state = IPCP_NULL; + ipcpi.shim_data = NULL; ipcpi.threadpool = malloc(sizeof(pthread_t) * IPCPD_THREADPOOL_SIZE); if (ipcpi.threadpool == NULL) { @@ -305,15 +307,6 @@ int ipcp_init(enum ipcp_type type, struct ipcp_ops * ops) ipcpi.ops = ops; - ipcpi.data = ipcp_data_create(); - if (ipcpi.data == NULL) { - free(ipcpi.threadpool); - free(ipcpi.sock_path); - return -ENOMEM; - } - - ipcp_data_init(ipcpi.data, type); - pthread_rwlock_init(&ipcpi.state_lock, NULL); pthread_mutex_init(&ipcpi.state_mtx, NULL); pthread_condattr_init(&cattr); @@ -322,6 +315,16 @@ int ipcp_init(enum ipcp_type type, struct ipcp_ops * ops) #endif pthread_cond_init(&ipcpi.state_cond, &cattr); + if (type == IPCP_NORMAL) + return 0; + + ipcpi.shim_data = shim_data_create(); + if (ipcpi.shim_data == NULL) { + free(ipcpi.threadpool); + free(ipcpi.sock_path); + return -ENOMEM; + } + return 0; } @@ -364,7 +367,7 @@ void ipcp_fini() free(ipcpi.sock_path); free(ipcpi.threadpool); - ipcp_data_destroy(ipcpi.data); + shim_data_destroy(ipcpi.shim_data); pthread_cond_destroy(&ipcpi.state_cond); pthread_mutex_destroy(&ipcpi.state_mtx); @@ -422,7 +425,8 @@ int ipcp_wait_state(enum ipcp_state state, return ret; } -int ipcp_parse_arg(int argc, char * argv[]) +int ipcp_parse_arg(int argc, + char * argv[]) { char * log_file; size_t len = 0; -- cgit v1.2.3