Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nginx/nginx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/os/unix
diff options
context:
space:
mode:
authorRuslan Ermilov <ru@nginx.com>2016-08-04 23:43:10 +0300
committerRuslan Ermilov <ru@nginx.com>2016-08-04 23:43:10 +0300
commit42f6e1f78e71557b7c6bee0cf77e000aa3c00f6d (patch)
treea67b3ec99148133d6b8a87d22319b25478df7377 /src/os/unix
parent31389e4921c81bd7a3b82a95032e60e13454bae4 (diff)
Always seed PRNG with PID, seconds, and milliseconds.
Diffstat (limited to 'src/os/unix')
-rw-r--r--src/os/unix/ngx_posix_init.c6
-rw-r--r--src/os/unix/ngx_process_cycle.c4
2 files changed, 7 insertions, 3 deletions
diff --git a/src/os/unix/ngx_posix_init.c b/src/os/unix/ngx_posix_init.c
index 76ed94e90..7e6e79d01 100644
--- a/src/os/unix/ngx_posix_init.c
+++ b/src/os/unix/ngx_posix_init.c
@@ -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;
}
diff --git a/src/os/unix/ngx_process_cycle.c b/src/os/unix/ngx_process_cycle.c
index 8c2d968a5..83b04ee62 100644
--- a/src/os/unix/ngx_process_cycle.c
+++ b/src/os/unix/ngx_process_cycle.c
@@ -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