summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--util/nvmutil/nvmutil.c33
1 files changed, 19 insertions, 14 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index 69a392fd..c9d9b4ca 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -113,9 +113,9 @@ static void set_err(int errval);
*/
#define items(x) (sizeof((x)) / sizeof((x)[0]))
+#ifndef HAVE_ARC4RANDOM_BUF
static const char newrandom[] = "/dev/urandom";
static const char oldrandom[] = "/dev/random"; /* fallback on OLD unix */
-#ifndef HAVE_ARC4RANDOM_BUF
static const char *rname = NULL;
#endif
@@ -357,21 +357,24 @@ open_dev_urandom(void)
{
struct stat st_urandom_fd;
+ /*
+ * Try /dev/urandom first
+ */
rname = newrandom;
+ if ((urandom_fd = open(rname, O_RDONLY)) != -1)
+ return;
- if ((urandom_fd = open(rname, O_RDONLY)) == -1) {
- /*
- * Fall back to /dev/random on old platforms
- * where /dev/urandom does not exist.
- *
- * We must reset the error condition first,
- * to prevent stale error status later.
- */
- errno = 0;
+ /*
+ * Fall back to /dev/random on old platforms
+ * where /dev/urandom does not exist.
+ *
+ * We must reset the error condition first,
+ * to prevent stale error status later.
+ */
+ errno = 0;
- rname = oldrandom;
- xopen(&urandom_fd, rname, O_RDONLY, &st_urandom_fd);
- }
+ rname = oldrandom;
+ xopen(&urandom_fd, rname, O_RDONLY, &st_urandom_fd);
}
#endif
@@ -872,8 +875,10 @@ write_gbe_file_part(size_t p)
static off_t
gbe_file_offset(size_t p, const char *f_op)
{
+ off_t gbe_file_half_size = gbe_file_size >> 1;
+
return gbe_x_offset(p, f_op, "file",
- gbe_file_size >> 1, gbe_file_size);
+ gbe_file_half_size, gbe_file_size);
}
/*