From af7441a66d1e3cfb43e0a00785b1636b927f40e6 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Sat, 24 Dec 2016 19:41:25 +0100 Subject: ipcpd: Use high resolution seed for flat policy This avoids normal ipcps using the flat address policy having a high probability for picking the same address when created from a script. --- src/ipcpd/normal/pol/flat.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/ipcpd/normal') diff --git a/src/ipcpd/normal/pol/flat.c b/src/ipcpd/normal/pol/flat.c index 0ab1e604..8a0570f8 100644 --- a/src/ipcpd/normal/pol/flat.c +++ b/src/ipcpd/normal/pol/flat.c @@ -133,9 +133,12 @@ int flat_init(void) { struct ro_attr rattr; pthread_condattr_t cattr; + struct timespec t; char * name; - srand(time(NULL)); + clock_gettime(CLOCK_REALTIME, &t); + + srand(t.tv_nsec); flat.addr_in_use = false; ro_attr_init(&rattr); -- cgit v1.2.3 From 5ae1fb3db5bf11ee2159b8461cdf1e54a2a0ef45 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Sun, 25 Dec 2016 11:20:16 +0100 Subject: ipcpd: Check for duplicate RO in flat addr policy --- src/ipcpd/normal/pol/flat.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/ipcpd/normal') diff --git a/src/ipcpd/normal/pol/flat.c b/src/ipcpd/normal/pol/flat.c index 8a0570f8..82c7db93 100644 --- a/src/ipcpd/normal/pol/flat.c +++ b/src/ipcpd/normal/pol/flat.c @@ -238,12 +238,22 @@ uint64_t flat_address(void) } pthread_mutex_lock(&flat.lock); + + if (ro_exists(ro_name)) { + pthread_mutex_unlock(&flat.lock); + free(ro_name); + free(buf); + continue; + } + + if (ro_create(ro_name, &attr, buf, sizeof(*msg))) { pthread_mutex_unlock(&flat.lock); free(ro_name); free(buf); return INVALID_ADDR; } + free(ro_name); while (flat.addr_in_use == false) { @@ -253,6 +263,7 @@ uint64_t flat_address(void) if (ret == -ETIMEDOUT) break; } + pthread_mutex_unlock(&flat.lock); } -- cgit v1.2.3