Bladeren bron

uac: use kam_rand() instead of rand()

- do kam_srand() when module is initialized
Daniel-Constantin Mierla 8 jaren geleden
bovenliggende
commit
219ddbb54b
2 gewijzigde bestanden met toevoegingen van 8 en 1 verwijderingen
  1. 6 0
      src/modules/uac/uac.c
  2. 2 1
      src/modules/uac/uac_reg.c

+ 6 - 0
src/modules/uac/uac.c

@@ -50,6 +50,7 @@
 #include "../../core/kemi.h"
 #include "../../core/kemi.h"
 #include "../../core/rpc.h"
 #include "../../core/rpc.h"
 #include "../../core/rpc_lookup.h"
 #include "../../core/rpc_lookup.h"
+#include "../../core/rand/kam_rand.h"
 #include "../../core/cfg/cfg_struct.h"
 #include "../../core/cfg/cfg_struct.h"
 #include "../dialog/dlg_load.h"
 #include "../dialog/dlg_load.h"
 
 
@@ -305,6 +306,7 @@ static int mod_init(void)
 
 
 	if(reg_db_url.s && reg_db_url.len>=0)
 	if(reg_db_url.s && reg_db_url.len>=0)
 	{
 	{
+		kam_srand(17 * getpid() + time(0));
 		if(!reg_contact_addr.s || reg_contact_addr.len<=0)
 		if(!reg_contact_addr.s || reg_contact_addr.len<=0)
 		{
 		{
 			LM_ERR("contact address parameter not set\n");
 			LM_ERR("contact address parameter not set\n");
@@ -343,6 +345,9 @@ error:
 static int child_init(int rank)
 static int child_init(int rank)
 {
 {
 	int pid;
 	int pid;
+
+	kam_srand((11 + rank) * getpid() * 17 +  time(0));
+
 	if (rank!=PROC_MAIN)
 	if (rank!=PROC_MAIN)
 		return 0;
 		return 0;
 
 
@@ -361,6 +366,7 @@ static int child_init(int rank)
 		if (cfg_child_init())
 		if (cfg_child_init())
 			return -1;
 			return -1;
 
 
+		kam_srand(getpid() * 17 +  time(0));
 		uac_reg_load_db();
 		uac_reg_load_db();
 		uac_reg_timer(0);
 		uac_reg_timer(0);
 		for(;;){
 		for(;;){

+ 2 - 1
src/modules/uac/uac_reg.c

@@ -43,6 +43,7 @@
 #include "../../core/parser/contact/parse_contact.h"
 #include "../../core/parser/contact/parse_contact.h"
 #include "../../core/rpc.h"
 #include "../../core/rpc.h"
 #include "../../core/rpc_lookup.h"
 #include "../../core/rpc_lookup.h"
+#include "../../core/rand/kam_rand.h"
 
 
 #include "../../modules/tm/tm_load.h"
 #include "../../modules/tm/tm_load.h"
 
 
@@ -538,7 +539,7 @@ int reg_ht_add(reg_uac_t *reg)
 	if (reg->reg_delay)
 	if (reg->reg_delay)
 		nr->reg_delay = reg->reg_delay;
 		nr->reg_delay = reg->reg_delay;
 	else if (reg_random_delay>0)
 	else if (reg_random_delay>0)
-		nr->reg_delay = rand() % reg_random_delay;
+		nr->reg_delay = kam_rand() % reg_random_delay;
 	nr->reg_init  = time(NULL);
 	nr->reg_init  = time(NULL);
 	nr->h_uuid = reg_compute_hash(&reg->l_uuid);
 	nr->h_uuid = reg_compute_hash(&reg->l_uuid);
 	nr->h_user = reg_compute_hash(&reg->l_username);
 	nr->h_user = reg_compute_hash(&reg->l_username);