On Fri, Aug 03, 2018 at 04:19:03PM +0300, Janne Blomqvist wrote:
> --- a/libgfortran/intrinsics/random.c
> +++ b/libgfortran/intrinsics/random.c
> @@ -309,12 +309,9 @@ getosrandom (void *buf, size_t buflen)
>    for (size_t i = 0; i < buflen / sizeof (unsigned int); i++)
>      rand_s (&b[i]);
>    return buflen;
> +#elif defined(HAVE_GETENTROPY)
> +  return getentropy (buf, buflen);
>  #else

I wonder if it wouldn't be better to use getentropy only if it is successful
and fall back to whatever you were doing before.

E.g. on Linux, I believe getentropy in glibc just uses the getrandom
syscall, which has only been introduced in Linux kernel 3.17.
So, if somebody is running glibc 2.25 or later on kernel < 3.17, it will
fail, even though reads from /dev/urandom could work.

> -  /*
> -     TODO: When glibc adds a wrapper for the getrandom() system call
> -     on Linux, one could use that.
> -
> -     TODO: One could use getentropy() on OpenBSD.  */
>    int flags = O_RDONLY;
>  #ifdef O_CLOEXEC
>    flags |= O_CLOEXEC;

        Jakub

Reply via email to