Skip to content

Commit

Permalink
portable srandomdev
Browse files Browse the repository at this point in the history
  • Loading branch information
Lev Walkin committed Nov 30, 2016
1 parent 2f3f094 commit 7d73356
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/tcpkali.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,22 @@ static struct multiplier bw_multiplier[] = {
};
/* clang-format on */

#ifndef HAVE_SRANDOMDEV
void portable_srandomdev() {
FILE *f = fopen("/dev/urandom", "rb");
if(f) {
unsigned int r;
if(fread(&r, sizeof(r), 1, f) == 1) {
fclose(f);
srandom(r);
return;
}
}
/* No usable /dev/urandom, too bad. */
srandom(getpid() ^ time(NULL) ^ atol(getenv("TCPKALI_RANDOM")?:"0"));
}
#endif

/*
* Parse command line options and kick off the engine.
*/
Expand All @@ -196,7 +212,7 @@ main(int argc, char **argv) {
#ifdef HAVE_SRANDOMDEV
srandomdev();
#else
srandom(time(NULL));
srandom(portable_srandomdev());
#endif

struct percentile_values latency_percentiles = {
Expand Down

0 comments on commit 7d73356

Please sign in to comment.