]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib_init(): Call srand() with a bit better seed.
authorTimo Sirainen <tss@iki.fi>
Thu, 2 Dec 2010 22:59:42 +0000 (22:59 +0000)
committerTimo Sirainen <tss@iki.fi>
Thu, 2 Dec 2010 22:59:42 +0000 (22:59 +0000)
src/lib/lib.c

index bb832e7dd08fae91abd1e8c2a56ec2c88a1c85d9..b9d87c7c8af4aa7e55314aa6f359097cc77b7841 100644 (file)
@@ -6,7 +6,8 @@
 #include "process-title.h"
 
 #include <stdlib.h>
-#include <time.h>
+#include <unistd.h>
+#include <sys/time.h>
 
 size_t nearest_power(size_t num)
 {
@@ -20,8 +21,12 @@ size_t nearest_power(size_t num)
 
 void lib_init(void)
 {
+       struct timeval tv;
+
        /* standard way to get rand() return different values. */
-       srand((unsigned int) time(NULL));
+       if (gettimeofday(&tv, NULL) < 0)
+               i_fatal("gettimeofday(): %m");
+       srand((unsigned int) (tv.tv_sec ^ tv.tv_usec ^ getpid()));
 
        data_stack_init();
        hostpid_init();