]> source.dussan.org Git - rspamd.git/commitdiff
Use more clever time values to setup entropy.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 2 Feb 2014 16:02:02 +0000 (16:02 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 3 Feb 2014 09:08:15 +0000 (09:08 +0000)
src/util.c

index 4a88bb1c92f3aa75b2c7d8573aa50bc27fdc7414..64f95c0d64ad600f8ef8d827bb15a0bf9c4013f4 100644 (file)
@@ -2138,6 +2138,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 */
@@ -2162,7 +2167,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;
        }