Mercurial > dovecot > core-2.2
view src/lib/rand.c @ 19604:c996bc091c6b
master: Do not close stdout if going foreground
This lets one to use /dev/stdout for logging. Mainly
useful for testing purposes where we can generate
log output to stdout and use tee to write it to a
file for later examination.
author | Aki Tuomi <aki.tuomi@dovecot.fi> |
---|---|
date | Mon, 18 Jan 2016 15:50:23 +0200 |
parents | 0f22db71df7a |
children | 2e2563132d5f |
line wrap: on
line source
/* Copyright (c) 2014-2016 Dovecot authors, see the included COPYING file */ /* Wrap srand() so that we can reproduce fuzzed tests */ #include "lib.h" static int seeded = 0; static unsigned int seed; static char const *env_seed; int rand_get_seed_count(void) { return seeded; } unsigned int rand_get_last_seed(void) { i_assert(seeded > 0); return seed; } void rand_set_seed(unsigned int s) { if (seeded == 0) { unsigned int seedval; env_seed = getenv("DOVECOT_SRAND"); if (env_seed != NULL && str_to_uint(env_seed, &seedval) >= 0) seed = seedval; } seeded++; if (env_seed == NULL) seed = s; srand(seed); }