diff options
author | Sander Vrijders <sander.vrijders@intec.ugent.be> | 2016-08-18 14:22:06 +0200 |
---|---|---|
committer | Sander Vrijders <sander.vrijders@intec.ugent.be> | 2016-08-19 13:24:39 +0200 |
commit | 2c8e29ca7a997c5aa9d34e3fa956b120a0bbf20c (patch) | |
tree | 6807a23a6def167a2b9ab26937fe25bbcc2a8064 /src/ipcpd/normal/main.c | |
parent | 0192488015770b4855165db8502214dad1941dd2 (diff) | |
download | ouroboros-2c8e29ca7a997c5aa9d34e3fa956b120a0bbf20c.tar.gz ouroboros-2c8e29ca7a997c5aa9d34e3fa956b120a0bbf20c.zip |
ipcpd: normal: Handle enrollment replies
This adds a condition variable with a timeout to the CDAP request so
that we can respond correctly to the answer from the remote. It also
adds a timeout to the condition variable waiting on completion of
enrollment. Furthermore, for every CDAP callback a new thread is now
spawned, to avoid deadlocking in case a callback is stuck.
Diffstat (limited to 'src/ipcpd/normal/main.c')
-rw-r--r-- | src/ipcpd/normal/main.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/ipcpd/normal/main.c b/src/ipcpd/normal/main.c index cf6ac728..4173246d 100644 --- a/src/ipcpd/normal/main.c +++ b/src/ipcpd/normal/main.c @@ -28,12 +28,14 @@ #include <ouroboros/shm_ap_rbuff.h> #include <ouroboros/dev.h> #include <ouroboros/ipcp.h> +#include <ouroboros/time_utils.h> #include <stdbool.h> #include <signal.h> #include <stdlib.h> #include <pthread.h> #include <string.h> +#include <errno.h> #include "fmgr.h" #include "ribmgr.h" @@ -131,6 +133,13 @@ static int normal_ipcp_name_unreg(char * name) static int normal_ipcp_enroll(char * dif_name) { + struct timespec timeout = {(ENROLL_TIMEOUT / 1000), + (ENROLL_TIMEOUT % 1000) * MILLION}; + struct timespec abstime; + + clock_gettime(PTHREAD_COND_CLOCK, &abstime); + ts_add(&abstime, &timeout, &abstime); + pthread_mutex_lock(&_ipcp->state_lock); if (_ipcp->state != IPCP_INIT) { @@ -147,10 +156,15 @@ static int normal_ipcp_enroll(char * dif_name) return -1; } - /* FIXME: Change into timedwait, see solution in irmd first */ pthread_mutex_lock(&_ipcp->state_lock); while (_ipcp->state != IPCP_ENROLLED) - pthread_cond_wait(&_ipcp->state_cond, &_ipcp->state_lock); + if (pthread_cond_timedwait(&_ipcp->state_cond, + &_ipcp->state_lock, + &abstime) == ETIMEDOUT) { + pthread_mutex_unlock(&_ipcp->state_lock); + LOG_ERR("Enrollment didn't complete in time."); + return -1; + } pthread_mutex_unlock(&_ipcp->state_lock); return 0; |