Browse code

core: update to use kam_rand()

Spencer Thomason authored on 07/07/2016 22:24:13
Showing 4 changed files
... ...
@@ -118,6 +118,7 @@
118 118
 #include "dst_blacklist.h"
119 119
 #endif
120 120
 #include "rand/fastrand.h" /* seed */
121
+#include "rand/kam_rand.h"
121 122
 
122 123
 #include "stats.h"
123 124
 #include "counters.h"
... ...
@@ -2103,10 +2104,10 @@ try_again:
2103 2103
 	}
2104 2104
 	seed+=getpid()+time(0);
2105 2105
 	LM_DBG("seeding PRNG with %u\n", seed);
2106
-	srand(seed);
2107
-	fastrand_seed(rand());
2108
-	srandom(rand()+time(0));
2109
-	LM_DBG("test random numbers %u %lu %u\n", rand(), random(), fastrand());
2106
+	kam_srand(seed);
2107
+	fastrand_seed(kam_rand());
2108
+	srandom(kam_rand()+time(0));
2109
+	LM_DBG("test random numbers %u %lu %u\n", kam_rand(), random(), fastrand());
2110 2110
 
2111 2111
 	/*register builtin  modules*/
2112 2112
 	register_builtin_modules();
... ...
@@ -103,6 +103,7 @@
103 103
 #include "parser/parse_param.h"
104 104
 #include "forward.h"
105 105
 #include "str_list.h"
106
+#include "rand/kam_rand.h"
106 107
 
107 108
 #define append_str_trans(_dest,_src,_len,_msg) \
108 109
 	append_str( (_dest), (_src), (_len) );
... ...
@@ -520,7 +521,7 @@ static inline int lump_check_opt(	struct lump *l,
520 520
 				return 1;
521 521
 			}
522 522
 		case COND_IF_RAND:
523
-			if(rand()>=RAND_MAX/2) {
523
+			if(kam_rand()>=KAM_RAND_MAX/2) {
524 524
 				LUMP_SET_COND_TRUE(l);
525 525
 				return 1;
526 526
 			} else return 0;
... ...
@@ -26,6 +26,7 @@
26 26
 #include "sr_module.h"
27 27
 #include "socket_info.h"
28 28
 #include "rand/fastrand.h"
29
+#include "rand/kam_rand.h"
29 30
 #ifdef PKG_MALLOC
30 31
 #include "mem/mem.h"
31 32
 #endif
... ...
@@ -284,7 +285,7 @@ int fork_process(int child_id, char *desc, int make_sock)
284 284
 	
285 285
 	
286 286
 	child_process_no = *process_count;
287
-	new_seed1=rand();
287
+	new_seed1=kam_rand();
288 288
 	new_seed2=random();
289 289
 	pid = fork();
290 290
 	if (pid<0) {
... ...
@@ -300,8 +301,8 @@ int fork_process(int child_id, char *desc, int make_sock)
300 300
 #ifdef USE_TCP
301 301
 		close_extra_socks(child_id, process_no);
302 302
 #endif /* USE_TCP */
303
-		srand(new_seed1);
304
-		fastrand_seed(rand());
303
+		kam_srand(new_seed1);
304
+		fastrand_seed(kam_rand());
305 305
 		srandom(new_seed2+time(0));
306 306
 		shm_malloc_on_fork();
307 307
 #ifdef PROFILING
... ...
@@ -419,7 +420,7 @@ int fork_tcp_process(int child_id, char *desc, int r, int *reader_fd_1)
419 419
 	
420 420
 	
421 421
 	child_process_no = *process_count;
422
-	new_seed1=rand();
422
+	new_seed1=kam_rand();
423 423
 	new_seed2=random();
424 424
 	pid = fork();
425 425
 	if (pid<0) {
... ...
@@ -442,8 +443,8 @@ int fork_tcp_process(int child_id, char *desc, int r, int *reader_fd_1)
442 442
 			}
443 443
 		}
444 444
 		daemon_status_on_fork_cleanup();
445
-		srand(new_seed1);
446
-		fastrand_seed(rand());
445
+		kam_srand(new_seed1);
446
+		fastrand_seed(kam_rand());
447 447
 		srandom(new_seed2+time(0));
448 448
 		shm_malloc_on_fork();
449 449
 #ifdef PROFILING
... ...
@@ -57,6 +57,7 @@
57 57
 #include "sr_module.h"
58 58
 #include "resolve.h"
59 59
 #include "forward.h"
60
+#include "rand/kam_rand.h"
60 61
 
61 62
 #define RETURN0_res(x) {*res=(x);return 0;}
62 63
 #define TRIM_RET0_res(x) {*res=(x);trim(res);return 0;} 
... ...
@@ -1508,11 +1509,11 @@ int select_sys_unique(str* res, select_t* s, struct sip_msg* msg) {
1508 1508
 		uniq_id[UNIQUE_ID_PID_LEN+1+UNIQUE_ID_TIME_LEN] = '-';
1509 1509
 
1510 1510
 		/* init random part */
1511
-		for (i = RAND_MAX, rb=0; i; rb++, i>>=1);
1511
+		for (i = KAM_RAND_MAX, rb=0; i; rb++, i>>=1);
1512 1512
 		for (i = UNIQUE_ID_FIX_LEN, cb = 0, x = 0; i < UNIQUE_ID_FIX_LEN+UNIQUE_ID_RAND_LEN; i++) {
1513 1513
 			if (!cb) {
1514 1514
 				cb = rb;
1515
-				x = rand();
1515
+				x = kam_rand();
1516 1516
 			}
1517 1517
 			uniq_id[i] = fourbits2char[x & 0x0F];
1518 1518
 			x >>= rb;