summaryrefslogtreecommitdiff
path: root/src/ipcpd/ipcp.c
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@intec.ugent.be>2017-02-07 20:45:14 +0100
committerdimitri staessens <dimitri.staessens@intec.ugent.be>2017-02-07 21:00:45 +0100
commitbfb86b66c8e7d9d8dc45d9075a4db6d10931dccf (patch)
tree022fbb7b2a54ba72affa12938b3bf79abc648b41 /src/ipcpd/ipcp.c
parent1bf2dd6aef3af6c81794c0551278373e44310b5c (diff)
downloadouroboros-bfb86b66c8e7d9d8dc45d9075a4db6d10931dccf.tar.gz
ouroboros-bfb86b66c8e7d9d8dc45d9075a4db6d10931dccf.zip
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.
Diffstat (limited to 'src/ipcpd/ipcp.c')
-rw-r--r--src/ipcpd/ipcp.c32
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;