[3.0] 01d04b5 Fall back to using current time if urandom is not available

Tollef Fog Heen tfheen at varnish-cache.org
Tue Aug 9 11:07:02 CEST 2011


commit 01d04b52baddb915bb074eff95b9a9ef2357f624
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