diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-16 15:10:49 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-26 06:59:41 +0000 |
| commit | 2a6a63fef3820804149c6e95c843cc29d99de969 (patch) | |
| tree | 2248887fa8be74fc3c92617263c827f5fc5bcfe3 /util | |
| parent | 609076d98b57018286be18f4efaf8955fa97c493 (diff) | |
util/nvmutil: better urandom portability
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util')
| -rw-r--r-- | util/nvmutil/nvmutil.c | 12 |
1 files changed, 9 insertions, 3 deletions
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; |
