From c78ada08adf7b6467912c3c4eedd7effa99b8991 Mon Sep 17 00:00:00 2001 From: Teemu Toivola Date: Sun, 25 Nov 2018 01:37:46 +0200 Subject: [PATCH] remove possible PollInterval and UpdateInterval drift over time, sync SaveInterval to full minutes --- CHANGES | 3 +++ src/daemon.c | 2 +- src/vnstatd.c | 4 ++-- tests/daemon_tests.c | 10 +++++----- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CHANGES b/CHANGES index 31a526b..afffa44 100644 --- a/CHANGES +++ b/CHANGES @@ -8,6 +8,9 @@ - Several typos and spelling mistakes in documentation - Daemon:waittimesync_does_not_wait_with_new_interfaces test was failing if the system used a time zone with a negative numeric value + - New + - Remove possible PollInterval and UpdateInterval drift over time + - Sync SaveInterval to full minutes 2.0 / 21-Oct-2018 diff --git a/src/daemon.c b/src/daemon.c index ad853f4..6ed5e32 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -415,7 +415,7 @@ void checkdbsaveneed(DSTATE *s) if ((s->current - s->prevdbsave) >= (s->saveinterval) || s->forcesave) { s->dodbsave = 1; s->forcesave = 0; - s->prevdbsave = s->current; + s->prevdbsave = s->current - (s->current % s->saveinterval); } else { s->dodbsave = 0; } diff --git a/src/vnstatd.c b/src/vnstatd.c index b054683..e40868f 100644 --- a/src/vnstatd.c +++ b/src/vnstatd.c @@ -242,7 +242,7 @@ int main(int argc, char *argv[]) /* update data cache */ } else { - s.prevdbupdate = s.current; + s.prevdbupdate = s.current - (s.current % s.updateinterval); adjustsaveinterval(&s); checkdbsaveneed(&s); @@ -256,7 +256,7 @@ int main(int argc, char *argv[]) } if (s.running && intsignal == 0) { - sleep((unsigned int)cfg.pollinterval); + sleep((unsigned int)(cfg.pollinterval - (time(NULL) % cfg.pollinterval))); } if (intsignal) { diff --git a/tests/daemon_tests.c b/tests/daemon_tests.c index 68eda0f..a7b9090 100644 --- a/tests/daemon_tests.c +++ b/tests/daemon_tests.c @@ -406,15 +406,15 @@ START_TEST(checkdbsaveneed_is_forced) DSTATE s; initdstate(&s); s.dodbsave = 2; - s.current = 10; - s.prevdbsave = 0; + s.current = 125; + s.prevdbsave = 110; s.saveinterval = 30; s.forcesave = 1; checkdbsaveneed(&s); ck_assert_int_eq(s.dodbsave, 1); - ck_assert_int_eq(s.prevdbsave, s.current); + ck_assert_int_eq(s.prevdbsave, 120); ck_assert_int_eq(s.forcesave, 0); } END_TEST @@ -424,7 +424,7 @@ START_TEST(checkdbsaveneed_needs) DSTATE s; initdstate(&s); s.dodbsave = 2; - s.current = 60; + s.current = 65; s.prevdbsave = 5; s.saveinterval = 30; s.forcesave = 0; @@ -432,7 +432,7 @@ START_TEST(checkdbsaveneed_needs) checkdbsaveneed(&s); ck_assert_int_eq(s.dodbsave, 1); - ck_assert_int_eq(s.prevdbsave, s.current); + ck_assert_int_eq(s.prevdbsave, 60); ck_assert_int_eq(s.forcesave, 0); } END_TEST -- 2.40.0