diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2022-07-18 12:39:01 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2022-07-18 12:39:01 +0000 |
commit | 69fb8c62a31e767be1464a7ccfe2a5bac331c4cc (patch) | |
tree | 5d444d670920f6ea7aaef36a426479541fdfb752 /src/librandom | |
parent | c555cd2ba1682f90fb5344d2865713fcd0f3c3e1 (diff) | |
download | skalibs-69fb8c62a31e767be1464a7ccfe2a5bac331c4cc.tar.xz |
Fix allread errno management
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/librandom')
-rw-r--r-- | src/librandom/random_devurandom.c | 4 |
1 files changed, 4 insertions, 0 deletions
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 <stddef.h> +#include <errno.h> #include <skalibs/allreadwrite.h> #include <skalibs/strerr2.h> @@ -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 ; } |