From patchwork Wed Sep 28 12:49:22 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Kleen X-Patchwork-Id: 116783 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id A785BB6F94 for ; Wed, 28 Sep 2011 22:49:58 +1000 (EST) Received: (qmail 4121 invoked by alias); 28 Sep 2011 12:49:53 -0000 Received: (qmail 4107 invoked by uid 22791); 28 Sep 2011 12:49:51 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from one.firstfloor.org (HELO one.firstfloor.org) (213.235.205.2) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 28 Sep 2011 12:49:27 +0000 Received: by one.firstfloor.org (Postfix, from userid 503) id 225EF1A9808D; Wed, 28 Sep 2011 14:49:26 +0200 (CEST) From: Andi Kleen To: gcc-patches@gcc.gnu.org Cc: Andi Kleen Subject: [PATCH 2/3] Use urandom to get random seed Date: Wed, 28 Sep 2011 14:49:22 +0200 Message-Id: <1317214163-26010-3-git-send-email-andi@firstfloor.org> In-Reply-To: <1317214163-26010-1-git-send-email-andi@firstfloor.org> References: <1317214163-26010-1-git-send-email-andi@firstfloor.org> Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org From: Andi Kleen 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 --- gcc/toplev.c | 12 +++++++++++- 1 files changed, 11 insertions(+), 1 deletions(-) diff --git a/gcc/toplev.c b/gcc/toplev.c index 78583fc..ab6b5a4 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;