From 2c8e29ca7a997c5aa9d34e3fa956b120a0bbf20c Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Thu, 18 Aug 2016 14:22:06 +0200 Subject: 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. --- src/ipcpd/normal/main.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/ipcpd/normal/main.c') 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 #include #include +#include #include #include #include #include #include +#include #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; -- cgit v1.2.3