ensure that the random number generator(s) are always seeded with a different value...
authorKevin P. Fleming <kpfleming@digium.com>
Wed, 13 Apr 2005 04:47:39 +0000 (04:47 +0000)
committerKevin P. Fleming <kpfleming@digium.com>
Wed, 13 Apr 2005 04:47:39 +0000 (04:47 +0000)
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
asterisk.c
channels/chan_iax2.c
pbx/pbx_dundi.c
res/res_musiconhold.c

index c47212a..f8558a3 100755 (executable)
@@ -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);
 }
 
index ee0bef9..562cf37 100755 (executable)
@@ -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);
index 40dbdb8..6c0608b 100755 (executable)
@@ -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();
index cae675c..1c198c0 100755 (executable)
@@ -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;
index ac6c0d5..6ba33b3 100755 (executable)
@@ -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;