Bläddra i källkod

core: update to use kam_rand()

Spencer Thomason 9 år sedan
förälder
incheckning
db11faca2a
4 ändrade filer med 17 tillägg och 13 borttagningar
  1. 5 4
      main.c
  2. 2 1
      msg_translator.c
  3. 7 6
      pt.c
  4. 3 2
      select_core.c

+ 5 - 4
main.c

@@ -118,6 +118,7 @@
 #include "dst_blacklist.h"
 #include "dst_blacklist.h"
 #endif
 #endif
 #include "rand/fastrand.h" /* seed */
 #include "rand/fastrand.h" /* seed */
+#include "rand/kam_rand.h"
 
 
 #include "stats.h"
 #include "stats.h"
 #include "counters.h"
 #include "counters.h"
@@ -2103,10 +2104,10 @@ try_again:
 	}
 	}
 	seed+=getpid()+time(0);
 	seed+=getpid()+time(0);
 	LM_DBG("seeding PRNG with %u\n", seed);
 	LM_DBG("seeding PRNG with %u\n", seed);
-	srand(seed);
-	fastrand_seed(rand());
-	srandom(rand()+time(0));
-	LM_DBG("test random numbers %u %lu %u\n", rand(), random(), fastrand());
+	kam_srand(seed);
+	fastrand_seed(kam_rand());
+	srandom(kam_rand()+time(0));
+	LM_DBG("test random numbers %u %lu %u\n", kam_rand(), random(), fastrand());
 
 
 	/*register builtin  modules*/
 	/*register builtin  modules*/
 	register_builtin_modules();
 	register_builtin_modules();

+ 2 - 1
msg_translator.c

@@ -103,6 +103,7 @@
 #include "parser/parse_param.h"
 #include "parser/parse_param.h"
 #include "forward.h"
 #include "forward.h"
 #include "str_list.h"
 #include "str_list.h"
+#include "rand/kam_rand.h"
 
 
 #define append_str_trans(_dest,_src,_len,_msg) \
 #define append_str_trans(_dest,_src,_len,_msg) \
 	append_str( (_dest), (_src), (_len) );
 	append_str( (_dest), (_src), (_len) );
@@ -520,7 +521,7 @@ static inline int lump_check_opt(	struct lump *l,
 				return 1;
 				return 1;
 			}
 			}
 		case COND_IF_RAND:
 		case COND_IF_RAND:
-			if(rand()>=RAND_MAX/2) {
+			if(kam_rand()>=KAM_RAND_MAX/2) {
 				LUMP_SET_COND_TRUE(l);
 				LUMP_SET_COND_TRUE(l);
 				return 1;
 				return 1;
 			} else return 0;
 			} else return 0;

+ 7 - 6
pt.c

@@ -26,6 +26,7 @@
 #include "sr_module.h"
 #include "sr_module.h"
 #include "socket_info.h"
 #include "socket_info.h"
 #include "rand/fastrand.h"
 #include "rand/fastrand.h"
+#include "rand/kam_rand.h"
 #ifdef PKG_MALLOC
 #ifdef PKG_MALLOC
 #include "mem/mem.h"
 #include "mem/mem.h"
 #endif
 #endif
@@ -284,7 +285,7 @@ int fork_process(int child_id, char *desc, int make_sock)
 	
 	
 	
 	
 	child_process_no = *process_count;
 	child_process_no = *process_count;
-	new_seed1=rand();
+	new_seed1=kam_rand();
 	new_seed2=random();
 	new_seed2=random();
 	pid = fork();
 	pid = fork();
 	if (pid<0) {
 	if (pid<0) {
@@ -300,8 +301,8 @@ int fork_process(int child_id, char *desc, int make_sock)
 #ifdef USE_TCP
 #ifdef USE_TCP
 		close_extra_socks(child_id, process_no);
 		close_extra_socks(child_id, process_no);
 #endif /* USE_TCP */
 #endif /* USE_TCP */
-		srand(new_seed1);
-		fastrand_seed(rand());
+		kam_srand(new_seed1);
+		fastrand_seed(kam_rand());
 		srandom(new_seed2+time(0));
 		srandom(new_seed2+time(0));
 		shm_malloc_on_fork();
 		shm_malloc_on_fork();
 #ifdef PROFILING
 #ifdef PROFILING
@@ -419,7 +420,7 @@ int fork_tcp_process(int child_id, char *desc, int r, int *reader_fd_1)
 	
 	
 	
 	
 	child_process_no = *process_count;
 	child_process_no = *process_count;
-	new_seed1=rand();
+	new_seed1=kam_rand();
 	new_seed2=random();
 	new_seed2=random();
 	pid = fork();
 	pid = fork();
 	if (pid<0) {
 	if (pid<0) {
@@ -442,8 +443,8 @@ int fork_tcp_process(int child_id, char *desc, int r, int *reader_fd_1)
 			}
 			}
 		}
 		}
 		daemon_status_on_fork_cleanup();
 		daemon_status_on_fork_cleanup();
-		srand(new_seed1);
-		fastrand_seed(rand());
+		kam_srand(new_seed1);
+		fastrand_seed(kam_rand());
 		srandom(new_seed2+time(0));
 		srandom(new_seed2+time(0));
 		shm_malloc_on_fork();
 		shm_malloc_on_fork();
 #ifdef PROFILING
 #ifdef PROFILING

+ 3 - 2
select_core.c

@@ -57,6 +57,7 @@
 #include "sr_module.h"
 #include "sr_module.h"
 #include "resolve.h"
 #include "resolve.h"
 #include "forward.h"
 #include "forward.h"
+#include "rand/kam_rand.h"
 
 
 #define RETURN0_res(x) {*res=(x);return 0;}
 #define RETURN0_res(x) {*res=(x);return 0;}
 #define TRIM_RET0_res(x) {*res=(x);trim(res);return 0;} 
 #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) {
 		uniq_id[UNIQUE_ID_PID_LEN+1+UNIQUE_ID_TIME_LEN] = '-';
 		uniq_id[UNIQUE_ID_PID_LEN+1+UNIQUE_ID_TIME_LEN] = '-';
 
 
 		/* init random part */
 		/* init random part */
-		for (i = RAND_MAX, rb=0; i; rb++, i>>=1);
+		for (i = KAM_RAND_MAX, rb=0; i; rb++, i>>=1);
 		for (i = UNIQUE_ID_FIX_LEN, cb = 0, x = 0; i < UNIQUE_ID_FIX_LEN+UNIQUE_ID_RAND_LEN; i++) {
 		for (i = UNIQUE_ID_FIX_LEN, cb = 0, x = 0; i < UNIQUE_ID_FIX_LEN+UNIQUE_ID_RAND_LEN; i++) {
 			if (!cb) {
 			if (!cb) {
 				cb = rb;
 				cb = rb;
-				x = rand();
+				x = kam_rand();
 			}
 			}
 			uniq_id[i] = fourbits2char[x & 0x0F];
 			uniq_id[i] = fourbits2char[x & 0x0F];
 			x >>= rb;
 			x >>= rb;