Skip to content

Commit

Permalink
uac: use kam_rand() instead of rand()
Browse files Browse the repository at this point in the history
- do kam_srand() when module is initialized

(cherry picked from commit 219ddbb)
  • Loading branch information
miconda committed Aug 30, 2017
1 parent 439daed commit c3ce7d2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/modules/uac/uac.c
Expand Up @@ -49,6 +49,7 @@
#include "../../core/mod_fix.h"
#include "../../core/rpc.h"
#include "../../core/rpc_lookup.h"
#include "../../core/rand/kam_rand.h"
#include "../../core/cfg/cfg_struct.h"
#include "../dialog/dlg_load.h"

Expand Down Expand Up @@ -304,6 +305,7 @@ static int mod_init(void)

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)
{
LM_ERR("contact address parameter not set\n");
Expand Down Expand Up @@ -342,6 +344,9 @@ static int mod_init(void)
static int child_init(int rank)
{
int pid;

kam_srand((11 + rank) * getpid() * 17 + time(0));

if (rank!=PROC_MAIN)
return 0;

Expand All @@ -360,6 +365,7 @@ static int child_init(int rank)
if (cfg_child_init())
return -1;

kam_srand(getpid() * 17 + time(0));
uac_reg_load_db();
uac_reg_timer(0);
for(;;){
Expand Down
3 changes: 2 additions & 1 deletion src/modules/uac/uac_reg.c
Expand Up @@ -43,6 +43,7 @@
#include "../../core/parser/contact/parse_contact.h"
#include "../../core/rpc.h"
#include "../../core/rpc_lookup.h"
#include "../../core/rand/kam_rand.h"

#include "../../modules/tm/tm_load.h"

Expand Down Expand Up @@ -538,7 +539,7 @@ int reg_ht_add(reg_uac_t *reg)
if (reg->reg_delay)
nr->reg_delay = reg->reg_delay;
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->h_uuid = reg_compute_hash(&reg->l_uuid);
nr->h_user = reg_compute_hash(&reg->l_username);
Expand Down

0 comments on commit c3ce7d2

Please sign in to comment.