diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-02-02 16:02:02 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-02-02 16:02:02 +0000 |
commit | 611b068491afcc16cce47fe6fedbfcdee5e67ca3 (patch) | |
tree | 4aa4406430f7a194318e6222a4d0d61dae646d67 /src | |
parent | 86c404040221355da70c368c1283473825957235 (diff) | |
download | rspamd-611b068491afcc16cce47fe6fedbfcdee5e67ca3.tar.gz rspamd-611b068491afcc16cce47fe6fedbfcdee5e67ca3.zip |
Use more clever time values to setup entropy.
Diffstat (limited to 'src')
-rw-r--r-- | src/util.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/util.c b/src/util.c index 2afda3546..3eed9a765 100644 --- a/src/util.c +++ b/src/util.c @@ -2115,6 +2115,11 @@ rspamd_random_bytes (gchar *buf, gsize buflen) { gint fd; gsize i; +#ifdef HAVE_CLOCK_GETTIME + struct timespec ts; +#else + struct timeval tv; +#endif #ifdef HAVE_OPENSSL /* Init random generator */ @@ -2139,7 +2144,13 @@ fallback: close (fd); } /* No /dev/random */ - g_random_set_seed (time (NULL)); +#ifdef HAVE_CLOCK_GETTIME + (void)clock_gettime (CLOCK_REALTIME, &ts); + g_random_set_seed (ts.tv_nsec); +#else + (void)gettimeofday (&tv, NULL); + g_random_set_seed (tv.tv_usec); +#endif for (i = 0; i < buflen; i ++) { buf[i] = g_random_int () & 0xff; } |