From 68ef78e439d9d15cab5b8f3a698b8770a60b7af7 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Mon, 16 Mar 2026 15:10:49 +0000 Subject: util/nvmutil: better urandom portability Signed-off-by: Leah Rowe --- util/nvmutil/nvmutil.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'util/nvmutil') diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index bab9ecfd..4d7c7dbb 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -305,6 +305,10 @@ typedef char static_assert_off_t_is_32[(sizeof(off_t) >= 4) ? 1 : -1]; #define O_BINARY 0 #endif +#ifndef O_NONBLOCK +#define O_NONBLOCK +#endif + #ifndef O_CLOEXEC #define O_CLOEXEC 0 #endif @@ -1382,9 +1386,11 @@ read_urandom(void) if (fd < 0) { - fd = open("/dev/urandom", O_RDONLY); - if (fd < 0) - fd = open("/dev/random", O_RDONLY); + fd = open("/dev/urandom", O_RDONLY | O_NONBLOCK); + if (fd < 0) /* older openbsd */ + fd = open("/dev/arandom", O_RDONLY | O_NONBLOCK); + if (fd < 0) /* super old unix (could block) */ + fd = open("/dev/random", O_RDONLY | O_NONBLOCK); if (fd < 0) return 16; -- cgit v1.2.1