From ef24bb21f91c066129d1fbb4fb72493029a17c6a Mon Sep 17 00:00:00 2001 From: Niko Tyni Date: Wed, 24 Oct 2012 21:04:53 +0200 Subject: As spotted by Gert Doering, rand() gives the same results in each pinger subprocess. This is because they all inherit the same RNG state from their parent. Fix this undesired behaviour by reseeding the RNG with the current time and the process ID. The argument of srand() shouldn't really matter much on modern Perls, but we're not very concerned about the quality of the random numbers either, and time()+$$ should make sure it's different for each process. --- lib/Smokeping/probes/basefork.pm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Smokeping/probes/basefork.pm b/lib/Smokeping/probes/basefork.pm index 0de7b6d..ed8fda8 100644 --- a/lib/Smokeping/probes/basefork.pm +++ b/lib/Smokeping/probes/basefork.pm @@ -201,6 +201,9 @@ sub ping { # we detach from the parent's process group setpgrp(0, $$); + # re-initialize the RNG for each subprocess + srand(time()+$$); + my @times = $self->pingone($t); print join(" ", @times), "\n"; exit; -- cgit v1.2.3-24-g4f1b