summaryrefslogtreecommitdiff
path: root/src/ipcpd/shim-udp
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@intec.ugent.be>2016-10-31 10:44:55 +0000
committerSander Vrijders <sander.vrijders@intec.ugent.be>2016-10-31 10:44:55 +0000
commit95ad15debb61e71561d9c6363bc6e8ae0927dce1 (patch)
tree4084ef29c666739372c1f7899b78cad21da91aa1 /src/ipcpd/shim-udp
parent94044e99af295e9440d306719a5cf341645d1803 (diff)
parentadd7d5f1e59c661b431ba86ba80d62badc14e762 (diff)
downloadouroboros-95ad15debb61e71561d9c6363bc6e8ae0927dce1.tar.gz
ouroboros-95ad15debb61e71561d9c6363bc6e8ae0927dce1.zip
Merged in dstaesse/ouroboros/be-fixes (pull request #294)
ipcpd: Clean shutdown when bootstrap fails
Diffstat (limited to 'src/ipcpd/shim-udp')
-rw-r--r--src/ipcpd/shim-udp/main.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/ipcpd/shim-udp/main.c b/src/ipcpd/shim-udp/main.c
index c90b47a2..503dbd0b 100644
--- a/src/ipcpd/shim-udp/main.c
+++ b/src/ipcpd/shim-udp/main.c
@@ -28,7 +28,6 @@
#include <ouroboros/dev.h>
#include <ouroboros/ipcp-dev.h>
#include <ouroboros/fqueue.h>
-#include <ouroboros/fcntl.h>
#include <ouroboros/errno.h>
#include <ouroboros/logs.h>
@@ -519,7 +518,11 @@ void ipcp_sig_handler(int sig, siginfo_t * info, void * c)
if (info->si_pid == irmd_api) {
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);
}
@@ -539,9 +542,6 @@ static int ipcp_udp_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);
-
if (inet_ntop(AF_INET,
&conf->ip_addr,
ipstr,
@@ -624,6 +624,9 @@ static int ipcp_udp_bootstrap(struct dif_config * conf)
pthread_rwlock_unlock(&ipcpi.state_lock);
+ /* this IPCP doesn't need to maintain its dif_name */
+ free(conf->dif_name);
+
LOG_DBG("Bootstrapped shim IPCP over UDP with api %d.", getpid());
LOG_DBG("Bound to IP address %s.", ipstr);
LOG_DBG("DNS server address is %s.", dnsstr);
@@ -1197,13 +1200,15 @@ int main(int argc, char * argv[])
ipcp_fini();
- pthread_cancel(udp_data.handler);
- pthread_cancel(udp_data.sdu_reader);
- pthread_cancel(udp_data.sduloop);
- pthread_join(udp_data.sduloop, NULL);
- pthread_join(udp_data.handler, NULL);
- pthread_join(udp_data.sdu_reader, NULL);
+ if (ipcp_get_state() == IPCP_SHUTDOWN) {
+ pthread_cancel(udp_data.handler);
+ pthread_cancel(udp_data.sdu_reader);
+ pthread_cancel(udp_data.sduloop);
+ pthread_join(udp_data.sduloop, NULL);
+ pthread_join(udp_data.handler, NULL);
+ pthread_join(udp_data.sdu_reader, NULL);
+ }
udp_data_fini();