From b3e9dadff2762af4c947e224c15ebbf7d6c5b618 Mon Sep 17 00:00:00 2001 From: Thananon Patinyasakdikul Date: Tue, 2 Aug 2016 16:54:24 -0700 Subject: [PATCH] libevent: use opal_random() instead of rand(3) This commits changed rand(3) and family in libevent to use internal random function provided in opal to prevent pertubing user's random seed. Fixes open-mpi/ompi#1877 --- opal/mca/event/libevent2022/configure.m4 | 7 ++++++- opal/util/alfg.c | 17 ++++++++++++++++- opal/util/alfg.h | 2 ++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/opal/mca/event/libevent2022/configure.m4 b/opal/mca/event/libevent2022/configure.m4 index 5ace9dc57d..66a5e778f1 100644 --- a/opal/mca/event/libevent2022/configure.m4 +++ b/opal/mca/event/libevent2022/configure.m4 @@ -159,8 +159,13 @@ AC_DEFUN([MCA_opal_event_libevent2022_CONFIG],[ AC_MSG_RESULT([$event_args]) + # We define "random" to be "opal_random" so that Libevent will not + # use random(3) internally (and potentially unexpectedly perturb + # values returned by rand(3) to the application). + + CPPFLAGS="$CPPFLAGS -Drandom=opal_random" OPAL_CONFIG_SUBDIR([$libevent_basedir/libevent], - [$event_args $opal_subdir_args], + [$event_args $opal_subdir_args 'CPPFLAGS=$CPPFLAGS'], [libevent_happy="yes"], [libevent_happy="no"]) if test "$libevent_happy" = "no"; then AC_MSG_WARN([Event library failed to configure]) diff --git a/opal/util/alfg.c b/opal/util/alfg.c index fc13f901f9..ccae7b5147 100644 --- a/opal/util/alfg.c +++ b/opal/util/alfg.c @@ -10,6 +10,8 @@ #include "opal_config.h" +#include + #include "alfg.h" /* Mask corresponding to the primitive polynomial @@ -52,6 +54,9 @@ static uint32_t galois(unsigned int *seed){ return lsb; } +/* OPAL global rng buffer */ +static opal_rng_buff_t alfg_buffer; + /** * @brief Routine to seed the ALFG register * @@ -80,6 +85,8 @@ int opal_srand(opal_rng_buff_t *buff, uint32_t seed) { buff->alfg[j] = buff->alfg[j] ^ ((galois(&seed_cpy))<