about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libmain/shared.cc6
-rw-r--r--src/libstore/local-store.cc2
2 files changed, 7 insertions, 1 deletions
diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc
index ead3fc017ae2..e869ef0379ad 100644
--- a/src/libmain/shared.cc
+++ b/src/libmain/shared.cc
@@ -10,6 +10,7 @@
 #include <cctype>
 #include <exception>
 
+#include <sys/time.h>
 #include <sys/stat.h>
 #include <unistd.h>
 
@@ -135,6 +136,11 @@ static void initAndRun(int argc, char * * argv)
        everybody. */
     umask(0022);
 
+    /* Initialise the PRNG. */
+    struct timeval tv;
+    gettimeofday(&tv, 0);
+    srandom(tv.tv_usec);
+
     /* Process the NIX_LOG_TYPE environment variable. */
     string lt = getEnv("NIX_LOG_TYPE");
     if (lt != "") setLogType(lt);
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index b4fc64d712fa..26b4cfd8c234 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -48,7 +48,7 @@ static void throwSQLiteError(sqlite3 * db, const format & f)
 #if HAVE_NANOSLEEP
         struct timespec t;
         t.tv_sec = 0;
-        t.tv_nsec = 100 * 1000 * 1000; /* 0.1s */
+        t.tv_nsec = (random() % 100) * 1000 * 1000; /* <= 0.1s */
         nanosleep(&t, 0);
 #else
         sleep(1);