]> granicus.if.org Git - vnstat/commitdiff
remove possible PollInterval and UpdateInterval drift over time, sync SaveInterval...
authorTeemu Toivola <git@humdi.net>
Sat, 24 Nov 2018 23:37:46 +0000 (01:37 +0200)
committerTeemu Toivola <git@humdi.net>
Sat, 24 Nov 2018 23:37:46 +0000 (01:37 +0200)
CHANGES
src/daemon.c
src/vnstatd.c
tests/daemon_tests.c

diff --git a/CHANGES b/CHANGES
index 31a526b46f6c751aedb9ec6fc29d83ea769419f2..afffa4411594984916397c9918d14c2d4d5ff172 100644 (file)
--- 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
index ad853f41492855ad9b8378966a485be6e27dc58b..6ed5e32f1c72a70bf99b26af73a9cb559f0ef2ac 100644 (file)
@@ -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;
        }
index b054683e2743285a9ed2757c2e0bde8d2afb9223..e40868fec9ffdebf92558681368727bcae77f854 100644 (file)
@@ -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) {
index 68eda0facb447909f8f1ee928f29123884138f65..a7b909094ff453b9b0c6863b7f5755cad21deca3 100644 (file)
@@ -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