diff options
author | Dimitri Staessens <[email protected]> | 2018-06-06 15:50:03 +0200 |
---|---|---|
committer | Sander Vrijders <[email protected]> | 2018-06-06 16:18:23 +0200 |
commit | 88f77ed5ef8d354664bac6d3c8af3d96cae640a4 (patch) | |
tree | 8c54c7a99485585e25510b3d5a9662673b34a77a /src/irmd/main.c | |
parent | e6ce5160d4de293e69e7d97ddc380ccbc59f16d5 (diff) | |
download | ouroboros-88f77ed5ef8d354664bac6d3c8af3d96cae640a4.tar.gz ouroboros-88f77ed5ef8d354664bac6d3c8af3d96cae640a4.zip |
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 <[email protected]>
Signed-off-by: Sander Vrijders <[email protected]>
Diffstat (limited to 'src/irmd/main.c')
-rw-r--r-- | src/irmd/main.c | 25 |
1 files 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; } |