diff options
author | Sander Vrijders <[email protected]> | 2017-02-07 20:07:17 +0000 |
---|---|---|
committer | Sander Vrijders <[email protected]> | 2017-02-07 20:07:17 +0000 |
commit | 9117f7f6fec70f2da24e8e77256747d11d67bf8d (patch) | |
tree | 022fbb7b2a54ba72affa12938b3bf79abc648b41 /src/ipcpd/ipcp.c | |
parent | 1bf2dd6aef3af6c81794c0551278373e44310b5c (diff) | |
parent | bfb86b66c8e7d9d8dc45d9075a4db6d10931dccf (diff) | |
download | ouroboros-9117f7f6fec70f2da24e8e77256747d11d67bf8d.tar.gz ouroboros-9117f7f6fec70f2da24e8e77256747d11d67bf8d.zip |
Merged in dstaesse/ouroboros/be-ipcp (pull request #363)
ipcpd: Refactor ipcpi struct
Diffstat (limited to 'src/ipcpd/ipcp.c')
-rw-r--r-- | src/ipcpd/ipcp.c | 32 |
1 files changed, 18 insertions, 14 deletions
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; |