From b052fe894bbcece8d93cc55327cf99455cc773cf Mon Sep 17 00:00:00 2001 From: "Kevin P. Fleming" Date: Wed, 13 Apr 2005 04:47:39 +0000 Subject: [PATCH] ensure that the random number generator(s) are always seeded with a different value during Asterisk startup don't reinitialize random number generators in other modules (bug #4017) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@5459 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- apps/app_random.c | 1 - asterisk.c | 6 ++++++ channels/chan_iax2.c | 1 - pbx/pbx_dundi.c | 3 --- res/res_musiconhold.c | 5 ++--- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/app_random.c b/apps/app_random.c index c47212a278..f8558a3b4a 100755 --- a/apps/app_random.c +++ b/apps/app_random.c @@ -106,7 +106,6 @@ int unload_module(void) int load_module(void) { - srandom((unsigned int)getpid() + (unsigned int)time(NULL)); return ast_register_application(app_random, random_exec, random_synopsis, random_descrip); } diff --git a/asterisk.c b/asterisk.c index ee0bef9a96..562cf3769d 100755 --- a/asterisk.c +++ b/asterisk.c @@ -1922,6 +1922,12 @@ int main(int argc, char *argv[]) signal(SIGCHLD, child_handler); signal(SIGPIPE, SIG_IGN); + /* ensure that the random number generators are seeded with a different value every time + Asterisk is started + */ + srand((unsigned int) getpid() + (unsigned int) time(NULL)); + srandom((unsigned int) getpid() + (unsigned int) time(NULL)); + if (init_logger()) { printf(term_quit()); exit(1); diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c index 40dbdb842d..6c0608bce7 100755 --- a/channels/chan_iax2.c +++ b/channels/chan_iax2.c @@ -8465,7 +8465,6 @@ static int reload_config(void) ast_clear_flag((&globalflags), IAX_NOTRANSFER); ast_clear_flag((&globalflags), IAX_USEJITTERBUF); ast_clear_flag((&globalflags), IAX_FORCEJITTERBUF); - srand(time(NULL)); delete_users(); set_config(config,1); prune_peers(); diff --git a/pbx/pbx_dundi.c b/pbx/pbx_dundi.c index cae675c17d..1c198c0e41 100755 --- a/pbx/pbx_dundi.c +++ b/pbx/pbx_dundi.c @@ -4632,9 +4632,6 @@ int load_module(void) dundi_set_output(dundi_debug_output); dundi_set_error(dundi_error_output); - /* Seed random number generator */ - srand(time(NULL)); - sin.sin_family = AF_INET; sin.sin_port = ntohs(DUNDI_PORT); sin.sin_addr.s_addr = INADDR_ANY; diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c index ac6c0d54da..6ba33b3caa 100755 --- a/res/res_musiconhold.c +++ b/res/res_musiconhold.c @@ -169,10 +169,9 @@ static int ast_moh_files_next(struct ast_channel *chan) state->pos++; } - if (ast_test_flag(state->class, MOH_RANDOMIZE)) { - srand(time(NULL)+getpid()+strlen(chan->name)-state->class->total_files); + if (ast_test_flag(state->class, MOH_RANDOMIZE)) state->pos = rand(); - } + /* check to see if this file's format can be opened */ if (ast_fileexists(state->class->filearray[state->pos], NULL, NULL) != -1) break;