From 31d1f8db15930774388d5ca798c6600fa8ededdf Mon Sep 17 00:00:00 2001
From: Alberto Bertogli <albertito@blitiri.com.ar>
Date: Mon, 15 Jun 2009 00:15:06 -0300
Subject: [PATCH 26/48] preload/posix: Seed the PRNG after initialization

Because we use random() to choose from possible errnos, we want it to be
properly seeded.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
---
 preload/posix/codegen.c |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/preload/posix/codegen.c b/preload/posix/codegen.c
index 8a9c349..a267d1c 100644
--- a/preload/posix/codegen.c
+++ b/preload/posix/codegen.c
@@ -1,6 +1,7 @@
 
 #include <stdio.h>
 #include <dlfcn.h>
+#include <sys/time.h>
 #include "codegen.h"
 
 /* Dynamically load libc */
@@ -22,3 +23,19 @@ static void __attribute__((constructor(200))) _fiu_init(void)
 	printd("done\n");
 }
 
+/* this runs after all function-specific constructors */
+static void __attribute__((constructor(250))) _fiu_init_final(void)
+{
+	struct timeval tv;
+
+	rec_inc();
+
+	fiu_init(0);
+
+	/* since we use random() in the wrappers, we need to seed it */
+	gettimeofday(&tv, NULL);
+	srandom(tv.tv_usec);
+
+	rec_dec();
+}
+
-- 
1.6.2.2.646.gb214

