]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
sched: update timeout randomization
authorMiroslav Lichvar <mlichvar@redhat.com>
Fri, 13 Nov 2015 15:08:02 +0000 (16:08 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Mon, 16 Nov 2015 09:30:59 +0000 (10:30 +0100)
Use UTI_GetRandomBytes() instead of random() to calculate the random
part of the timeout. This was the only remaining use of random() in the
code and the srandom() call can be removed.

sched.c

diff --git a/sched.c b/sched.c
index f9720c07d31b7ba22e28661c659f5e27089fa0de..773aab8bd8ee84aa494ea9a5a1738671debacbd6 100644 (file)
--- a/sched.c
+++ b/sched.c
@@ -150,8 +150,6 @@ SCH_Initialise(void)
   LCL_ReadRawTime(&last_select_ts_raw);
   last_select_ts = last_select_ts_raw;
 
-  srandom(last_select_ts.tv_sec << 16 ^ last_select_ts.tv_usec);
-
   initialised = 1;
 }
 
@@ -376,7 +374,10 @@ SCH_AddTimeoutInClass(double min_delay, double separation, double randomness,
   assert(class < SCH_NumberOfClasses);
 
   if (randomness > 0.0) {
-    r = random() % 0xffff / (0xffff - 1.0) * randomness + 1.0;
+    uint16_t rnd;
+
+    UTI_GetRandomBytes(&rnd, sizeof (rnd));
+    r = rnd / (double)0xffff * randomness + 1.0;
     min_delay *= r;
     separation *= r;
   }