Call srand() only once during initialization

SVN revision: 2253
This commit is contained in:
Stefan Ritt 2009-09-01 07:05:34 +00:00
parent 7cb5f15e1d
commit 9aaf751db1

View File

@ -13290,7 +13290,6 @@ void show_forgot_pwd_page(LOGBOOK * lbs)
} }
/* create random password */ /* create random password */
srand((unsigned int) time(NULL));
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
str[i] = 'A' + (rand() % 25); str[i] = 'A' + (rand() % 25);
str[i] = 0; str[i] = 0;
@ -15004,7 +15003,6 @@ int submit_message(LOGBOOK * lbs, char *host, int message_id, char *error_str)
content = xmalloc(content_length); content = xmalloc(content_length);
/* compose content */ /* compose content */
srand((unsigned) time(NULL));
sprintf(boundary, "---------------------------%04X%04X%04X", rand(), rand(), rand()); sprintf(boundary, "---------------------------%04X%04X%04X", rand(), rand(), rand());
strcpy(content, boundary); strcpy(content, boundary);
strcat(content, "\r\nContent-Disposition: form-data; name=\"cmd\"\r\n\r\nSubmit\r\n"); strcat(content, "\r\nContent-Disposition: form-data; name=\"cmd\"\r\n\r\nSubmit\r\n");
@ -15350,7 +15348,6 @@ void submit_config(LOGBOOK * lbs, char *server, char *buffer, char *error_str)
content = xmalloc(content_length); content = xmalloc(content_length);
/* compose content */ /* compose content */
srand((unsigned) time(NULL));
sprintf(boundary, "---------------------------%04X%04X%04X", rand(), rand(), rand()); sprintf(boundary, "---------------------------%04X%04X%04X", rand(), rand(), rand());
strcpy(content, boundary); strcpy(content, boundary);
strcat(content, "\r\nContent-Disposition: form-data; name=\"cmd\"\r\n\r\nSave\r\n"); strcat(content, "\r\nContent-Disposition: form-data; name=\"cmd\"\r\n\r\nSave\r\n");
@ -28003,6 +28000,9 @@ void server_loop(void)
if (_abort) if (_abort)
break; break;
/* call random number generator on each access to completely randomize it */
rand();
/* close old connections */ /* close old connections */
for (i = 0; i < N_MAX_CONNECTION; i++) for (i = 0; i < N_MAX_CONNECTION; i++)
if (ka_sock[i] && (int) time(NULL) - ka_time[i] > 60) { if (ka_sock[i] && (int) time(NULL) - ka_time[i] > 60) {
@ -28923,6 +28923,9 @@ int main(int argc, char *argv[])
use_keepalive = TRUE; use_keepalive = TRUE;
running_as_daemon = FALSE; running_as_daemon = FALSE;
/* initialize random number generator */
srand((unsigned) time(NULL));
/* /*
* Initially, redirect all messages handled with eprintf/efputs to stderr. * Initially, redirect all messages handled with eprintf/efputs to stderr.
* Note that we should use eprintf/efputs wrappers for all logging purposes, * Note that we should use eprintf/efputs wrappers for all logging purposes,