From 88f77ed5ef8d354664bac6d3c8af3d96cae640a4 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Wed, 6 Jun 2018 15:50:03 +0200 Subject: irmd: Retry bind for live processes If bind was called before the process registered with the IRMd, the bind operation would fail. The IRMd will now wait for a short period until the process is registered or exits. Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- src/irmd/main.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/irmd/main.c b/src/irmd/main.c index 19bcc8c5..574223b0 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -69,6 +69,7 @@ #define SHM_SAN_HOLDOFF 1000 /* ms */ #define IPCP_HASH_LEN(e) hash_len(e->dir_hash_algo) #define IB_LEN SOCK_BUF_SIZE +#define BIND_TIMEOUT 10 /* ms */ enum init_state { IPCP_NULL = 0, @@ -758,18 +759,32 @@ static int bind_program(char * prog, static int bind_process(pid_t pid, char * name) { - char * name_dup = NULL; - struct proc_entry * e = NULL; - struct reg_entry * re = NULL; + char * name_dup = NULL; + struct proc_entry * e = NULL; + struct reg_entry * re = NULL; + struct timespec now; + struct timespec dl = {0, 10 * MILLION}; if (name == NULL) return -EINVAL; + clock_gettime(PTHREAD_COND_CLOCK, &now); + + ts_add(&dl, &now, &dl); + pthread_rwlock_wrlock(&irmd.reg_lock); - e = proc_table_get(&irmd.proc_table, pid); + while (!kill(pid, 0)) { + e = proc_table_get(&irmd.proc_table, pid); + if (e != NULL || ts_diff_ms(&now, &dl) > 0) + break; + clock_gettime(PTHREAD_COND_CLOCK, &now); + sched_yield(); + } + if (e == NULL) { - log_err("Process %d does not exist.", pid); + log_err("Process %d does not %s.", pid, + kill(pid, 0) ? "exist" : "respond"); pthread_rwlock_unlock(&irmd.reg_lock); return -1; } -- cgit v1.2.3