[experimental-ims] 939d229 Seed random() on startup from /dev/urandom so vtmpfile actually returns random file names
Geoff Simmons
geoff at varnish-cache.org
Fri Jul 8 11:47:34 CEST 2011
commit 939d2299c51c8af03b663185b79c49e3d7833d86
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date: Fri Jun 10 09:43:48 2011 +0200
Seed random() on startup from /dev/urandom so vtmpfile actually
returns random file names
diff --git a/bin/varnishd/varnishd.c b/bin/varnishd/varnishd.c
index 9dae7d3..ded54ae 100644
--- a/bin/varnishd/varnishd.c
+++ b/bin/varnishd/varnishd.c
@@ -364,6 +364,8 @@ main(int argc, char * const *argv)
for (o = getdtablesize(); o > STDERR_FILENO; o--)
(void)close(o);
+ AZ(seed_random());
+
mgt_got_fd(STDERR_FILENO);
setbuf(stdout, NULL);
diff --git a/include/libvarnish.h b/include/libvarnish.h
index afa9f2f..317dc9e 100644
--- a/include/libvarnish.h
+++ b/include/libvarnish.h
@@ -99,6 +99,7 @@ struct timeval TIM_timeval(double t);
void VCS_Message(const char *);
/* from libvarnish/vtmpfile.c */
+int seed_random(void);
int vtmpfile(char *);
char *vreadfile(const char *pfx, const char *fn, ssize_t *sz);
char *vreadfd(int fd, ssize_t *sz);
diff --git a/lib/libvarnish/vtmpfile.c b/lib/libvarnish/vtmpfile.c
index 63dde2d..60a9c21 100644
--- a/lib/libvarnish/vtmpfile.c
+++ b/lib/libvarnish/vtmpfile.c
@@ -41,6 +41,22 @@
#include "libvarnish.h"
int
+seed_random(void)
+{
+ int fd;
+ unsigned seed;
+
+ fd = open("/dev/urandom", O_RDONLY);
+ if (fd == -1)
+ return (1);
+ if (read(fd, &seed, sizeof seed) != sizeof seed)
+ return (1);
+ (void)close(fd);
+ srandom(seed);
+ return (0);
+}
+
+int
vtmpfile(char *template)
{
char *b, *e, *p;
More information about the varnish-commit
mailing list