Permalink
Browse files

Always seed PRNG with PID, seconds, and milliseconds.

  • Loading branch information...
Ruslan Ermilov
Ruslan Ermilov committed Aug 4, 2016
1 parent 31389e4 commit 42f6e1f78e71557b7c6bee0cf77e000aa3c00f6d
@@ -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;
}
@@ -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
@@ -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;
@@ -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;
}

0 comments on commit 42f6e1f

Please sign in to comment.