+       rv = random();
        pthread_mutex_unlock(&rand_mutex); 
        if (rv < 0)
                return rv;

But random_r() is accessed only via get_rand, using a mutex, so it looks
like we can replace it with random.

But why not use random() only when random_r() is not available?


The random_r family of functions and they seem to be a glibc extension.
There are random_r/random/, initstate_r/initstate and `static struct
random_data rand_data' required to be split by macro (such as
HAVE_RANDOM_R), and add AC_CHECK_FUNCS([random_r]) to configure.ac to
generate the macro HAVE_RANDOM_R according to the existence of random_r,
but we do not have configure.ac in sanlock :(

Or we can use  macro `__GLIBC__' to figure out glibc and other libc, but it also
make the source more complicated.

//Hongxu

Nir
 

-       return a + (int) (((float)(b - a + 1)) * val / (RAND_MAX+1.0));
+       return a + (int) (((float)(b - a + 1)) * rv / (RAND_MAX+1.0));
 }

 static void setup_host_name(void)
@@ -1405,9 +1403,7 @@ static void setup_host_name(void)
        uuid_t uu;

        memset(rand_state, 0, sizeof(rand_state));
-       memset(&rand_data, 0, sizeof(rand_data));
-
-       initstate_r(time(NULL), rand_state, sizeof(rand_state), &rand_data);
+       initstate(time(NULL), rand_state, sizeof(rand_state));

        /* use host name from command line */

--
2.8.1
_______________________________________________
sanlock-devel mailing list -- sanlock-devel@lists.fedorahosted.org
To unsubscribe send an email to sanlock-devel-leave@lists.fedorahosted.org
Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedorahosted.org/archives/list/sanlock-devel@lists.fedorahosted.org