Mercurial > dovecot > core-2.2
changeset 12492:8e30a07d8dd0
lib_init(): Call srand() with a bit better seed.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 02 Dec 2010 22:59:42 +0000 |
parents | 6c9bc37fcf41 |
children | b7d13ee51aa4 |
files | src/lib/lib.c |
diffstat | 1 files changed, 7 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/lib.c Thu Dec 02 21:42:30 2010 +0000 +++ b/src/lib/lib.c Thu Dec 02 22:59:42 2010 +0000 @@ -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 @@ 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();