summaryrefslogtreecommitdiff
path: root/src/ipcpd/local
diff options
context:
space:
mode:
Diffstat (limited to 'src/ipcpd/local')
-rw-r--r--src/ipcpd/local/main.c40
1 files changed, 24 insertions, 16 deletions
diff --git a/src/ipcpd/local/main.c b/src/ipcpd/local/main.c
index 412795ec..f0c85084 100644
--- a/src/ipcpd/local/main.c
+++ b/src/ipcpd/local/main.c
@@ -26,7 +26,6 @@
#include <ouroboros/logs.h>
#include <ouroboros/errno.h>
#include <ouroboros/dev.h>
-#include <ouroboros/fcntl.h>
#include <ouroboros/fqueue.h>
#include <ouroboros/ipcp-dev.h>
#include <ouroboros/local-dev.h>
@@ -38,7 +37,6 @@
#include <stdlib.h>
#include <pthread.h>
#include <sys/wait.h>
-#include <fcntl.h>
#include <assert.h>
#define EVENT_WAIT_TIMEOUT 100 /* us */
@@ -90,14 +88,10 @@ static void * ipcp_local_sdu_loop(void * o)
(void) o;
- while (true) {
+ while (flow_event_wait(local_data.flows, local_data.fq, &timeout)) {
int fd;
ssize_t idx;
- if (flow_event_wait(local_data.flows, local_data.fq, &timeout)
- == -ETIMEDOUT)
- continue;
-
pthread_rwlock_rdlock(&ipcpi.state_lock);
if (ipcp_get_state() != IPCP_ENROLLED) {
@@ -140,7 +134,11 @@ void ipcp_sig_handler(int sig, siginfo_t * info, void * c)
pthread_rwlock_wrlock(&ipcpi.state_lock);
- ipcp_set_state(IPCP_SHUTDOWN);
+ if (ipcp_get_state() == IPCP_INIT)
+ ipcp_set_state(IPCP_NULL);
+
+ if (ipcp_get_state() == IPCP_ENROLLED)
+ ipcp_set_state(IPCP_SHUTDOWN);
pthread_rwlock_unlock(&ipcpi.state_lock);
}
@@ -154,9 +152,6 @@ static int ipcp_local_bootstrap(struct dif_config * conf)
assert(conf);
assert(conf->type == THIS_TYPE);
- /* this IPCP doesn't need to maintain its dif_name */
- free(conf->dif_name);
-
pthread_rwlock_wrlock(&ipcpi.state_lock);
if (ipcp_get_state() != IPCP_INIT) {
@@ -165,6 +160,9 @@ static int ipcp_local_bootstrap(struct dif_config * conf)
return -1;
}
+ /* this IPCP doesn't need to maintain its dif_name */
+ free(conf->dif_name);
+
ipcp_set_state(IPCP_ENROLLED);
pthread_create(&local_data.sduloop, NULL, ipcp_local_sdu_loop, NULL);
@@ -231,7 +229,8 @@ static int ipcp_local_flow_alloc(int fd,
LOG_DBG("Allocating flow to %s on fd %d.", dst_name, fd);
- assert(dst_name || src_ae_name);
+ assert(dst_name);
+ assert(src_ae_name);
pthread_rwlock_rdlock(&ipcpi.state_lock);
@@ -296,17 +295,24 @@ static int ipcp_local_flow_dealloc(int fd)
ipcp_flow_fini(fd);
pthread_rwlock_rdlock(&ipcpi.state_lock);
+
+ if (ipcp_get_state() != IPCP_ENROLLED) {
+ pthread_rwlock_unlock(&ipcpi.state_lock);
+ LOG_DBG("Won't register with non-enrolled IPCP.");
+ return -1; /* -ENOTENROLLED */
+ }
+
pthread_rwlock_wrlock(&local_data.lock);
flow_set_del(local_data.flows, fd);
local_data.in_out[fd] = -1;
+ flow_dealloc(fd);
+
pthread_rwlock_unlock(&local_data.lock);
pthread_rwlock_unlock(&ipcpi.state_lock);
- flow_dealloc(fd);
-
LOG_INFO("Flow with fd %d deallocated.", fd);
return 0;
@@ -382,8 +388,10 @@ int main(int argc, char * argv[])
ipcp_fini();
- pthread_cancel(local_data.sduloop);
- pthread_join(local_data.sduloop, NULL);
+ if (ipcp_get_state() == IPCP_SHUTDOWN) {
+ pthread_cancel(local_data.sduloop);
+ pthread_join(local_data.sduloop, NULL);
+ }
local_data_fini();