[master] 39249ec Fall back to using current time if urandom is not available

Tollef Fog Heen tfheen at varnish-cache.org
Fri Jul 15 12:21:27 CEST 2011


commit 39249ecefaa8ed19bc261b6c6ae27997cf0a1a63
Author: Tollef Fog Heen <tfheen at varnish-software.com>
Date:   Fri Jul 15 12:14:08 2011 +0200

    Fall back to using current time if urandom is not available

diff --git a/lib/libvarnish/vtmpfile.c b/lib/libvarnish/vtmpfile.c
index 60a9c21..327790a 100644
--- a/lib/libvarnish/vtmpfile.c
+++ b/lib/libvarnish/vtmpfile.c
@@ -35,6 +35,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <time.h>
 
 #include <sys/stat.h>
 
@@ -47,8 +48,12 @@ seed_random(void)
 	unsigned seed;
 
 	fd = open("/dev/urandom", O_RDONLY);
-	if (fd == -1)
-		return (1);
+	if (fd == -1) {
+		/* urandom not available, fall back to something
+		 * weaker */
+		srandom(time(NULL));
+		return (0);
+	}
 	if (read(fd, &seed, sizeof seed) != sizeof seed)
 		return (1);
 	(void)close(fd);



More information about the varnish-commit mailing list