summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiko Tyni <ntyni@debian.org>2012-10-24 21:04:53 +0200
committerTobias Oetiker <tobi@oetiker.ch>2012-10-24 21:04:53 +0200
commitef24bb21f91c066129d1fbb4fb72493029a17c6a (patch)
tree7a41372896f023cb55bb3486b65648d10a6d198d
parent49572f3da6f0e62adbcb3d326c698fad941164f4 (diff)
downloadsmokeping-ef24bb21f91c066129d1fbb4fb72493029a17c6a.tar.gz
smokeping-ef24bb21f91c066129d1fbb4fb72493029a17c6a.tar.xz
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.
-rw-r--r--lib/Smokeping/probes/basefork.pm3
1 files changed, 3 insertions, 0 deletions
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;