diff options
author | Sander Vrijders <[email protected]> | 2017-01-04 16:43:24 +0100 |
---|---|---|
committer | Sander Vrijders <[email protected]> | 2017-01-04 16:43:24 +0100 |
commit | c9b54bcd27fe87559f82b9a1cebba9b38abf5ebc (patch) | |
tree | 8190cda7271de35bae0725240e29ea33fce1ddc3 /src/ipcpd/ipcp.c | |
parent | bbabc773eccf7fe414428b3c8e4a7d3521ca7582 (diff) | |
parent | 4384cd203a958373cf0ab959afb688f9eeba05fc (diff) | |
download | ouroboros-c9b54bcd27fe87559f82b9a1cebba9b38abf5ebc.tar.gz ouroboros-c9b54bcd27fe87559f82b9a1cebba9b38abf5ebc.zip |
Merged in dstaesse/ouroboros/be-ipcpd (pull request #336)
ipcpd: Add boot and shutdown operations
Diffstat (limited to 'src/ipcpd/ipcp.c')
-rw-r--r-- | src/ipcpd/ipcp.c | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/src/ipcpd/ipcp.c b/src/ipcpd/ipcp.c index c47f1181..e44fafe2 100644 --- a/src/ipcpd/ipcp.c +++ b/src/ipcpd/ipcp.c @@ -279,13 +279,12 @@ static void * ipcp_main_loop(void * o) int ipcp_init(enum ipcp_type type, struct ipcp_ops * ops) { pthread_condattr_t cattr; - int t; struct timeval tv = {(IPCP_ACCEPT_TIMEOUT / 1000), (IPCP_ACCEPT_TIMEOUT % 1000) * 1000}; ipcpi.irmd_fd = -1; - ipcpi.state = IPCP_INIT; + ipcpi.state = IPCP_NULL; ipcpi.threadpool = malloc(sizeof(pthread_t) * IPCPD_THREADPOOL_SIZE); if (ipcpi.threadpool == NULL) { @@ -329,20 +328,40 @@ int ipcp_init(enum ipcp_type type, struct ipcp_ops * ops) #endif pthread_cond_init(&ipcpi.state_cond, &cattr); - for (t = 0; t < IPCPD_THREADPOOL_SIZE; ++t) - pthread_create(&ipcpi.threadpool[t], NULL, - ipcp_main_loop, NULL); - return 0; } -void ipcp_fini() +int ipcp_boot() { int t; + for (t = 0; t < IPCPD_THREADPOOL_SIZE; ++t) { + if (pthread_create(&ipcpi.threadpool[t], NULL, + ipcp_main_loop, NULL)) { + int i; + LOG_ERR("Failed to create main thread."); + ipcp_set_state(IPCP_NULL); + for (i = 0; i < t; ++i) + pthread_join(ipcpi.threadpool[i], NULL); + return -1; + } + } + + ipcpi.state = IPCP_INIT; + return 0; +} + +void ipcp_shutdown() +{ + int t; for (t = 0; t < IPCPD_THREADPOOL_SIZE; ++t) pthread_join(ipcpi.threadpool[t], NULL); + LOG_DBG("IPCP %d shutting down. Bye.", getpid()); +} + +void ipcp_fini() +{ close(ipcpi.sockfd); if (unlink(ipcpi.sock_path)) LOG_DBG("Could not unlink %s.", ipcpi.sock_path); @@ -353,6 +372,7 @@ void ipcp_fini() ipcp_data_destroy(ipcpi.data); pthread_cond_destroy(&ipcpi.state_cond); + pthread_mutex_destroy(&ipcpi.state_mtx); pthread_rwlock_destroy(&ipcpi.state_lock); } |