r3366 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Mon Nov 10 10:29:53 CET 2008


Author: phk
Date: 2008-11-10 10:29:52 +0100 (Mon, 10 Nov 2008)
New Revision: 3366

Modified:
   trunk/varnish-cache/bin/varnishd/cache_center.c
Log:
Add a debug CLI command to seed random(3).

This is a lot less useful than it could have been, as the Open Group
only mandates that:

	Like rand(), random() shall produce by default a sequence
	of numbers that can be duplicated by calling srandom() with
	1 as the seed.

But crucially leaves out *which* sequence of numbers.



Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c	2008-11-09 14:26:24 UTC (rev 3365)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c	2008-11-10 09:29:52 UTC (rev 3366)
@@ -1055,9 +1055,23 @@
 	cli_out(cli, "XID is %u", xids);
 }
 
+static void
+cli_debug_srandom(struct cli *cli, const char * const *av, void *priv)
+{
+	(void)priv;
+	unsigned long seed;
+
+	if (av[2] != NULL)
+		seed = strtoul(av[2], NULL, 0);
+	srandom(seed);
+	cli_out(cli, "Random(3) seeded with %lu", seed);
+}
+
 static struct cli_proto debug_cmds[] = {
 	{ "debug.xid", "debug.xid",
 		"\tExamine or set XID\n", 0, 1, cli_debug_xid },
+	{ "debug.srandom", "debug.srandom",
+		"\tSeed the random(3) function\n", 0, 1, cli_debug_srandom },
 	{ NULL }
 };
 




More information about the varnish-commit mailing list