diff options
author | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-08-19 16:16:39 +0200 |
---|---|---|
committer | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-08-19 16:16:39 +0200 |
commit | ba27593e3e8406e109393ae383f17c7416675c1e (patch) | |
tree | 6807a23a6def167a2b9ab26937fe25bbcc2a8064 /src/ipcpd/normal/main.c | |
parent | 0192488015770b4855165db8502214dad1941dd2 (diff) | |
parent | 2c8e29ca7a997c5aa9d34e3fa956b120a0bbf20c (diff) | |
download | ouroboros-ba27593e3e8406e109393ae383f17c7416675c1e.tar.gz ouroboros-ba27593e3e8406e109393ae383f17c7416675c1e.zip |
Merged in sandervrijders/ouroboros/be-enroll-failures (pull request #212)
ipcpd: normal: Handle enrollment replies
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; |