r766 - in trunk/varnish-cache: . include include/compat lib/libcompat

des at projects.linpro.no des at projects.linpro.no
Tue Aug 8 14:15:22 CEST 2006


Author: des
Date: 2006-08-08 14:15:22 +0200 (Tue, 08 Aug 2006)
New Revision: 766

Added:
   trunk/varnish-cache/include/compat/srandomdev.h
   trunk/varnish-cache/lib/libcompat/srandomdev.c
Modified:
   trunk/varnish-cache/configure.ac
   trunk/varnish-cache/include/Makefile.am
   trunk/varnish-cache/lib/libcompat/Makefile.am
Log:
Add a simple srandomdev() implementation inspired by the one in FreeBSD.

Modified: trunk/varnish-cache/configure.ac
===================================================================
--- trunk/varnish-cache/configure.ac	2006-08-08 09:15:18 UTC (rev 765)
+++ trunk/varnish-cache/configure.ac	2006-08-08 12:15:22 UTC (rev 766)
@@ -61,6 +61,7 @@
 AC_CHECK_FUNCS([strerror])
 AC_FUNC_STRERROR_R
 AC_CHECK_FUNCS([socket])
+AC_CHECK_FUNCS([srandomdev])
 AC_CHECK_FUNCS([strlcat])
 AC_CHECK_FUNCS([strlcpy])
 

Modified: trunk/varnish-cache/include/Makefile.am
===================================================================
--- trunk/varnish-cache/include/Makefile.am	2006-08-08 09:15:18 UTC (rev 765)
+++ trunk/varnish-cache/include/Makefile.am	2006-08-08 12:15:22 UTC (rev 766)
@@ -6,6 +6,7 @@
 	cli_common.h \
 	cli_priv.h \
 	compat/asprintf.h \
+	compat/srandomdev.h \
 	compat/strlcat.h \
 	compat/strlcpy.h \
 	compat/vasprintf.h \

Added: trunk/varnish-cache/include/compat/srandomdev.h
===================================================================
--- trunk/varnish-cache/include/compat/srandomdev.h	2006-08-08 09:15:18 UTC (rev 765)
+++ trunk/varnish-cache/include/compat/srandomdev.h	2006-08-08 12:15:22 UTC (rev 766)
@@ -0,0 +1,12 @@
+/*
+ * $Id$
+ */
+
+#ifndef COMPAT_SRANDOMDEV_H_INCLUDED
+#define COMPAT_SRANDOMDEV_H_INCLUDED
+
+#ifndef HAVE_SRANDOMDEV
+void srandomdev(void);
+#endif
+
+#endif


Property changes on: trunk/varnish-cache/include/compat/srandomdev.h
___________________________________________________________________
Name: svn:keywords
   + Id

Modified: trunk/varnish-cache/lib/libcompat/Makefile.am
===================================================================
--- trunk/varnish-cache/lib/libcompat/Makefile.am	2006-08-08 09:15:18 UTC (rev 765)
+++ trunk/varnish-cache/lib/libcompat/Makefile.am	2006-08-08 12:15:22 UTC (rev 766)
@@ -7,6 +7,7 @@
 libcompat_a_SOURCES = \
 	asprintf.c \
 	vasprintf.c \
+	srandomdev.c \
 	strlcat.c \
 	strlcpy.c
 

Added: trunk/varnish-cache/lib/libcompat/srandomdev.c
===================================================================
--- trunk/varnish-cache/lib/libcompat/srandomdev.c	2006-08-08 09:15:18 UTC (rev 765)
+++ trunk/varnish-cache/lib/libcompat/srandomdev.c	2006-08-08 12:15:22 UTC (rev 766)
@@ -0,0 +1,33 @@
+/*
+ * $Id$
+ */
+
+#ifndef HAVE_SRANDOMDEV
+
+#include <sys/time.h>
+
+#include <fcntl.h>
+#include <stdlib.h>
+#include <time.h>
+#include <unistd.h>
+
+#include "compat/srandomdev.h"
+
+void
+srandomdev(void)
+{
+	struct timeval tv;
+	unsigned int seed;
+	int fd;
+
+	if ((fd = open("/dev/random", O_RDONLY)) >= 0) {
+		read(fd, &seed, sizeof seed);
+		close(fd);
+	} else {
+		gettimeofday(&tv, NULL);
+		/* NOTE: intentional use of uninitialized variable */
+		seed ^= (getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec;
+	}
+	srandom(seed);
+}
+#endif


Property changes on: trunk/varnish-cache/lib/libcompat/srandomdev.c
___________________________________________________________________
Name: svn:keywords
   + Id




More information about the varnish-commit mailing list