summaryrefslogtreecommitdiff
path: root/src/librandom/random_init.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2020-12-04 14:40:52 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2020-12-04 14:40:52 +0000
commit2ddd93b4423b94578868e2701c265f8da4350965 (patch)
tree9994c48d0a67b169623d69ed16edc44910e21429 /src/librandom/random_init.c
parent38da4384d3b4630787430b9b38bd4726e00cc7d9 (diff)
downloadskalibs-2ddd93b4423b94578868e2701c265f8da4350965.tar.xz
Fix iobufferk_init on recent Linux; remove last superfluous coe
Diffstat (limited to 'src/librandom/random_init.c')
-rw-r--r--src/librandom/random_init.c18
1 files changed, 5 insertions, 13 deletions
diff --git a/src/librandom/random_init.c b/src/librandom/random_init.c
index e780cfa..e47f8df 100644
--- a/src/librandom/random_init.c
+++ b/src/librandom/random_init.c
@@ -6,6 +6,7 @@
#include <skalibs/nonposix.h>
#include <stdlib.h>
+
#include <skalibs/random.h>
int random_init ()
@@ -45,29 +46,20 @@ SURFSchedule surf_here = SURFSCHEDULE_ZERO ;
#ifdef SKALIBS_HASDEVURANDOM
#include <errno.h>
+
#include <skalibs/djbunix.h>
int random_fd = -1 ;
int random_init ()
{
- int fd ;
char seed[160] ;
+ if (random_fd >= 0) return 1 ;
random_makeseed(seed) ;
surf_init(&surf_here, seed) ;
openwritenclose_unsafe("/dev/urandom", seed, 160) ;
- if (random_fd < 0)
- {
- fd = open_readb("/dev/urandom") ;
- if (fd < 0) return 0 ;
- if (coe(fd) < 0)
- {
- fd_close(fd) ;
- return 0 ;
- }
- random_fd = fd ;
- }
- return 1 ;
+ random_fd = openc_readb("/dev/urandom") ;
+ return random_fd >= 0 ;
}
#else /* default */