]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Use urandom to get random seed
authorAndi Kleen <ak@linux.intel.com>
Thu, 29 Sep 2011 13:15:13 +0000 (13:15 +0000)
committerAndi Kleen <ak@gcc.gnu.org>
Thu, 29 Sep 2011 13:15:13 +0000 (13:15 +0000)
When available use /dev/urandom to get the random seem. This will lower the probability
of collisions.

On other systems it will fallback to the old methods.

Passes bootstrap + testsuite on x86_64. Ok?

gcc/:

2011-09-26   Andi Kleen <ak@linux.intel.com>

* toplev.c (init_local_tick): Try reading random seed from /dev/urandom

From-SVN: r179348

gcc/ChangeLog
gcc/toplev.c

index c0c963c4daa8d2e90457543f91cbd1b111cbea52..67afcd5ceb1a961c3935d9165c861e2ea317c3cf 100644 (file)
@@ -1,3 +1,7 @@
+2011-09-26   Andi Kleen <ak@linux.intel.com>
+
+       * toplev.c (init_local_tick): Try reading random seed from /dev/urandom
+
 2011-09-26   Andi Kleen <ak@linux.intel.com>
 
        * hwint.h (HOST_WIDE_INT_PRINT_HEX_PURE): Add.
index 78583fc52a683c6511855ffe976ea4fba68751d5..ab6b5a418378fc5ffc3828fc41432a1cfec25602 100644 (file)
@@ -262,7 +262,17 @@ init_local_tick (void)
 {
   if (!flag_random_seed)
     {
-      /* Get some more or less random data.  */
+      /* Try urandom first. Time of day is too likely to collide. 
+        In case of any error we just use the local tick. */
+
+      int fd = open ("/dev/urandom", O_RDONLY);
+      if (fd >= 0)
+        {
+          read (fd, &random_seed, sizeof (random_seed));
+          close (fd);
+        }
+
+      /* Now get the tick anyways  */
 #ifdef HAVE_GETTIMEOFDAY
       {
        struct timeval tv;