summaryrefslogtreecommitdiff
path: root/util/nvmutil/nvmutil.c
diff options
context:
space:
mode:
Diffstat (limited to 'util/nvmutil/nvmutil.c')
-rw-r--r--util/nvmutil/nvmutil.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index 77b33aa2..38d34436 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -141,9 +141,12 @@ rhex(void)
{
static int rfd = -1, n = 0;
static uint8_t rnum[16];
- xopen(rfd, "/dev/urandom", O_RDONLY);
- if (!n)
+ if (!n) {
+ if (rfd == -1) {
+ xopen(rfd, "/dev/urandom", O_RDONLY);
+ }
xpread(rfd, (uint8_t *) &rnum, (n = 15) + 1, 0, "/dev/urandom");
+ }
return rnum[n--] & 0xf;
}