From: Andi Kleen Date: Thu, 29 Sep 2011 13:15:13 +0000 (+0000) Subject: Use urandom to get random seed X-Git-Tag: releases/gcc-4.7.0~3469 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=35f2a89d8ec65fe11c37f1c681f465229bc852e3;p=thirdparty%2Fgcc.git Use urandom to get random seed 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 * toplev.c (init_local_tick): Try reading random seed from /dev/urandom From-SVN: r179348 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c0c963c4daa8..67afcd5ceb1a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,7 @@ +2011-09-26 Andi Kleen + + * toplev.c (init_local_tick): Try reading random seed from /dev/urandom + 2011-09-26 Andi Kleen * hwint.h (HOST_WIDE_INT_PRINT_HEX_PURE): Add. diff --git a/gcc/toplev.c b/gcc/toplev.c index 78583fc52a68..ab6b5a418378 100644 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -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;