Always seed PRNG with PID, seconds, and milliseconds.

This commit is contained in:
Ruslan Ermilov 2016-08-04 23:43:10 +03:00
parent 31389e4921
commit 42f6e1f78e
4 changed files with 19 additions and 11 deletions

View File

@ -33,7 +33,8 @@ ngx_os_io_t ngx_os_io = {
ngx_int_t
ngx_os_init(ngx_log_t *log)
{
ngx_uint_t n;
ngx_time_t *tp;
ngx_uint_t n;
#if (NGX_HAVE_OS_SPECIFIC_INIT)
if (ngx_os_specific_init(log) != NGX_OK) {
@ -76,7 +77,8 @@ ngx_os_init(ngx_log_t *log)
ngx_inherited_nonblocking = 0;
#endif
srandom(ngx_time());
tp = ngx_timeofday();
srandom(((unsigned) ngx_pid << 16) ^ tp->sec ^ tp->msec);
return NGX_OK;
}

View File

@ -785,6 +785,7 @@ ngx_worker_process_init(ngx_cycle_t *cycle, ngx_int_t worker)
{
sigset_t set;
ngx_int_t n;
ngx_time_t *tp;
ngx_uint_t i;
ngx_cpuset_t *cpu_affinity;
struct rlimit rlmt;
@ -884,7 +885,8 @@ ngx_worker_process_init(ngx_cycle_t *cycle, ngx_int_t worker)
"sigprocmask() failed");
}
srandom(((unsigned) ngx_pid << 16) ^ ngx_time());
tp = ngx_timeofday();
srandom(((unsigned) ngx_pid << 16) ^ tp->sec ^ tp->msec);
/*
* disable deleting previous events for the listening sockets because

View File

@ -762,9 +762,11 @@ static ngx_thread_value_t __stdcall
ngx_worker_thread(void *data)
{
ngx_int_t n;
ngx_time_t *tp;
ngx_cycle_t *cycle;
srand((ngx_pid << 16) ^ (unsigned) ngx_time());
tp = ngx_timeofday();
srand((ngx_pid << 16) ^ (unsigned) tp->sec ^ tp->msec);
cycle = (ngx_cycle_t *) ngx_cycle;

View File

@ -59,12 +59,13 @@ static GUID dx_guid = WSAID_DISCONNECTEX;
ngx_int_t
ngx_os_init(ngx_log_t *log)
{
DWORD bytes;
SOCKET s;
WSADATA wsd;
ngx_err_t err;
ngx_uint_t n;
SYSTEM_INFO si;
DWORD bytes;
SOCKET s;
WSADATA wsd;
ngx_err_t err;
ngx_time_t *tp;
ngx_uint_t n;
SYSTEM_INFO si;
/* get Windows version */
@ -237,7 +238,8 @@ ngx_os_init(ngx_log_t *log)
ngx_sprintf((u_char *) ngx_unique, "%P%Z", ngx_pid);
}
srand((ngx_pid << 16) ^ (unsigned) ngx_time());
tp = ngx_timeofday();
srand((ngx_pid << 16) ^ (unsigned) tp->sec ^ tp->msec);
return NGX_OK;
}