summaryrefslogtreecommitdiff
path: root/networking/ntpd.c
diff options
context:
space:
mode:
authorDenys Vlasenko2014-02-09 15:35:04 +0100
committerDenys Vlasenko2014-02-09 15:35:04 +0100
commit3e78f6f955ebdc010bb0b8f78622bf701e594b69 (patch)
tree6ea197099918a1894fe5119208a5e0b779ac8ce1 /networking/ntpd.c
parent8ed96726603a59969b99e4ea30dbd9b06955084b (diff)
downloadbusybox-3e78f6f955ebdc010bb0b8f78622bf701e594b69.zip
busybox-3e78f6f955ebdc010bb0b8f78622bf701e594b69.tar.gz
htpd: trivial simplification in random interval selection
function old new delta poll_interval 57 52 -5 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/ntpd.c')
-rw-r--r--networking/ntpd.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/networking/ntpd.c b/networking/ntpd.c
index 03fe448..bf8ef0a 100644
--- a/networking/ntpd.c
+++ b/networking/ntpd.c
@@ -1660,13 +1660,14 @@ retry_interval(void)
static unsigned
poll_interval(int exponent)
{
- unsigned interval, r;
+ unsigned interval, r, mask;
exponent = G.poll_exp + exponent;
if (exponent < 0)
exponent = 0;
interval = 1 << exponent;
+ mask = ((interval-1) >> 4) | 1;
r = random();
- interval += ((r & (interval-1)) >> 4) + ((r >> 8) & 1); /* + 1/16 of interval, max */
+ interval += r & mask; /* ~ random(0..1) * interval/16 */
VERB4 bb_error_msg("chose poll interval:%u (poll_exp:%d exp:%d)", interval, G.poll_exp, exponent);
return interval;
}