Commit 939d2299 authored by Martin Blix Grydeland's avatar Martin Blix Grydeland

Seed random() on startup from /dev/urandom so vtmpfile actually

returns random file names
parent d81cc9b5
......@@ -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);
......
......@@ -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);
......
......@@ -40,6 +40,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)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment