Merge pull request #657 from stoeckmann/getrandom

Use GRND_NONBLOCK with getrandom.
This commit is contained in:
Eric Hawicz
2020-08-15 15:01:41 -04:00
committed by GitHub

View File

@@ -164,19 +164,21 @@ retry:
static int get_getrandom_seed(void)
{
DEBUG_SEED("get_dev_random_seed");
DEBUG_SEED("get_getrandom_seed");
int r;
ssize_t ret;
do {
ret = getrandom(&r, sizeof(r), 0);
ret = getrandom(&r, sizeof(r), GRND_NONBLOCK);
} while ((ret == -1) && (errno == EINTR));
if (ret == -1)
{
if (errno == ENOSYS) /* syscall not available in kernel */
return -1;
if (errno == EAGAIN) /* entropy not yet initialized */
return -1;
fprintf(stderr, "error from getrandom(): %s", strerror(errno));
exit(1);