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.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index 8495836f..e6f43da6 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -1051,15 +1051,18 @@ rlong(void)
if (fd < 0)
fd = open("/dev/random", O_RDONLY | O_BINARY | O_NONBLOCK);
- nr = rw_file_exact(fd, (unsigned char *)&rval,
- sizeof(unsigned long), 0, IO_READ, LOOP_EAGAIN,
- LOOP_EINTR, MAX_ZERO_RW_RETRY, OFF_ERR);
+ if (fd > -1) {
- if (x_i_close(fd) < 0)
- err(errno, "Can't close randomness fd");
+ nr = rw_file_exact(fd, (unsigned char *)&rval,
+ sizeof(unsigned long), 0, IO_READ, LOOP_EAGAIN,
+ LOOP_EINTR, MAX_ZERO_RW_RETRY, OFF_ERR);
- if (nr == sizeof(unsigned long))
- return rval;
+ if (x_i_close(fd) < 0)
+ err(errno, "Can't close randomness fd");
+
+ if (nr == sizeof(unsigned long))
+ return rval;
+ }
return mix;
}