From 69fb8c62a31e767be1464a7ccfe2a5bac331c4cc Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Mon, 18 Jul 2022 12:39:01 +0000 Subject: Fix allread errno management Signed-off-by: Laurent Bercot --- src/librandom/random_devurandom.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/librandom') diff --git a/src/librandom/random_devurandom.c b/src/librandom/random_devurandom.c index 0ad752b..5f6b791 100644 --- a/src/librandom/random_devurandom.c +++ b/src/librandom/random_devurandom.c @@ -1,6 +1,7 @@ /* ISC license. */ #include +#include #include #include @@ -11,12 +12,15 @@ void random_devurandom (char *s, size_t n) { static int random_fd = -1 ; size_t r ; + int e = errno ; if (random_fd < 0) { random_fd = openbc_read("/dev/urandom") ; if (random_fd < 0) strerr_diefu2sys(111, "open ", "/dev/urandom") ; } + errno = EPIPE ; r = allread(random_fd, s, n) ; if (r < n) strerr_diefu2sys(111, "read from ", "/dev/urandom") ; + errno = e ; } -- cgit v1.2.3