aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2010-01-06 17:18:57 +0000
committerGerald Combs <gerald@wireshark.org>2010-01-06 17:18:57 +0000
commit066dd47c5294f4cfa0acedd8779153ab0e187d6c (patch)
treef374edf04c5e6837930ed56032f29e19c1fdc044
parentbd55fda74cba50fea397fab30028000d4c1cd9bc (diff)
Use /dev/urandom (which is non-blocking) instead of /dev/random (which
can block forever) for our seed. This fixes a problem with our new Linux build slave, which is running Linux 2.6 as a VM guest, and which was timing out waiting for entropy. Add a comment about using CryptGenRandom on Windows. svn path=/trunk/; revision=31456
-rw-r--r--randpkt.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/randpkt.c b/randpkt.c
index a018265112..4b6644fa68 100644
--- a/randpkt.c
+++ b/randpkt.c
@@ -688,17 +688,19 @@ seed(void)
int fd;
ssize_t ret;
+#define RANDOM_DEV "/dev/urandom"
+
/*
- * Assume it's at least worth trying /dev/random on UN*X.
+ * Assume it's at least worth trying /dev/urandom on UN*X.
* If it doesn't exist, fall back on time().
*
- * XXX - does Windows have a system source of entropy?
+ * XXX - Use CryptGenRandom on Windows?
*/
- fd = open("/dev/random", O_RDONLY);
+ fd = open(RANDOM_DEV, O_RDONLY);
if (fd == -1) {
if (errno != ENOENT) {
fprintf(stderr,
- "randpkt: Could not open /dev/random for reading: %s\n",
+ "randpkt: Could not open " RANDOM_DEV " for reading: %s\n",
strerror(errno));
exit(2);
}
@@ -708,13 +710,13 @@ seed(void)
ret = read(fd, &randomness, sizeof randomness);
if (ret == -1) {
fprintf(stderr,
- "randpkt: Could not read from /dev/random: %s\n",
+ "randpkt: Could not read from " RANDOM_DEV ": %s\n",
strerror(errno));
exit(2);
}
if ((size_t)ret != sizeof randomness) {
fprintf(stderr,
- "randpkt: Tried to read %lu bytes from /dev/random, got %ld\n",
+ "randpkt: Tried to read %lu bytes from " RANDOM_DEV ", got %ld\n",
(unsigned long)sizeof randomness, (long)ret);
exit(2);
}