From: Paul Eggert Date: Sat, 9 Jan 2021 01:54:30 +0000 (-0800) Subject: tempname: don’t block for minutes X-Git-Tag: v1.0~3175 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=b0ebaf83a49fe4a895a78ddf5b0c4a029e34c566;p=gnulib.git tempname: don’t block for minutes Derived from a patch proposed by Adhemerval Zanella in: https://sourceware.org/pipermail/libc-alpha/2021-January/121302.html * lib/tempname.c (random_bits): Use GRND_NONBLOCK. --- diff --git a/ChangeLog b/ChangeLog index 812888f8e5..b76330e5b6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2021-01-08 Paul Eggert + tempname: don’t block for minutes + Derived from a patch proposed by Adhemerval Zanella in: + https://sourceware.org/pipermail/libc-alpha/2021-January/121302.html + * lib/tempname.c (random_bits): Use GRND_NONBLOCK. + tempname: sync with proposed glibc patch This is from Adhemerval Zanella in: https://sourceware.org/pipermail/libc-alpha/2021-January/121301.html diff --git a/lib/tempname.c b/lib/tempname.c index f196b98622..f199b25a7a 100644 --- a/lib/tempname.c +++ b/lib/tempname.c @@ -80,10 +80,11 @@ static random_value random_bits (random_value var) { random_value r; - if (__getrandom (&r, sizeof r, 0) == sizeof r) + /* Without GRND_NONBLOCK it can be blocked for minutes on some systems. */ + if (__getrandom (&r, sizeof r, GRND_NONBLOCK) == sizeof r) return r; #if _LIBC || (defined CLOCK_MONOTONIC && HAVE_CLOCK_GETTIME) - /* Add entropy if getrandom is not supported. */ + /* Add entropy if getrandom did not work. */ struct __timespec64 tv; __clock_gettime64 (CLOCK_MONOTONIC, &tv); var ^= tv.tv_nsec;