diff options
Diffstat (limited to 'src/lib/libc')
| -rw-r--r-- | src/lib/libc/net/res_random.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/lib/libc/net/res_random.c b/src/lib/libc/net/res_random.c index f28692f7c2..394072c813 100644 --- a/src/lib/libc/net/res_random.c +++ b/src/lib/libc/net/res_random.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: res_random.c,v 1.21 2014/07/20 04:22:34 guenther Exp $ */ | 1 | /* $OpenBSD: res_random.c,v 1.22 2015/06/04 19:26:39 eric Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de> | 4 | * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de> |
| @@ -101,6 +101,7 @@ static u_int16_t ru_counter = 0; | |||
| 101 | static u_int16_t ru_msb = 0; | 101 | static u_int16_t ru_msb = 0; |
| 102 | static struct prf_ctx *ru_prf = NULL; | 102 | static struct prf_ctx *ru_prf = NULL; |
| 103 | static time_t ru_reseed; | 103 | static time_t ru_reseed; |
| 104 | static pid_t ru_pid; | ||
| 104 | 105 | ||
| 105 | static u_int16_t pmod(u_int16_t, u_int16_t, u_int16_t); | 106 | static u_int16_t pmod(u_int16_t, u_int16_t, u_int16_t); |
| 106 | static void res_initid(void); | 107 | static void res_initid(void); |
| @@ -227,15 +228,19 @@ u_int | |||
| 227 | res_randomid(void) | 228 | res_randomid(void) |
| 228 | { | 229 | { |
| 229 | struct timespec ts; | 230 | struct timespec ts; |
| 231 | pid_t pid; | ||
| 230 | u_int r; | 232 | u_int r; |
| 231 | _THREAD_PRIVATE_MUTEX(random); | 233 | _THREAD_PRIVATE_MUTEX(random); |
| 232 | 234 | ||
| 233 | clock_gettime(CLOCK_MONOTONIC, &ts); | 235 | clock_gettime(CLOCK_MONOTONIC, &ts); |
| 236 | pid = getpid(); | ||
| 234 | 237 | ||
| 235 | _THREAD_PRIVATE_MUTEX_LOCK(random); | 238 | _THREAD_PRIVATE_MUTEX_LOCK(random); |
| 236 | 239 | ||
| 237 | if (ru_counter >= RU_MAX || ts.tv_sec > ru_reseed) | 240 | if (ru_counter >= RU_MAX || ts.tv_sec > ru_reseed || pid != ru_pid) { |
| 238 | res_initid(); | 241 | res_initid(); |
| 242 | ru_pid = pid; | ||
| 243 | } | ||
| 239 | 244 | ||
| 240 | /* Linear Congruential Generator */ | 245 | /* Linear Congruential Generator */ |
| 241 | ru_x = (ru_a * ru_x + ru_b) % RU_M; | 246 | ru_x = (ru_a * ru_x + ru_b) % RU_M; |
