]> git.itanic.dy.fi Git - rrdd/commitdiff
rrtdool: Simplify sleeptime calculation
authorTimo Kokkonen <timo.t.kokkonen@iki.fi>
Sat, 21 Nov 2020 09:41:00 +0000 (11:41 +0200)
committerTimo Kokkonen <timo.t.kokkonen@iki.fi>
Sat, 21 Nov 2020 09:41:00 +0000 (11:41 +0200)
The code can be refactored into understandable form with less lines.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
rrdtool.c

index df189505f541a624379cf8671c6bd0a86ebef3da..f570f5c981d77cbfafac03acdda50eec5c44a206 100644 (file)
--- a/rrdtool.c
+++ b/rrdtool.c
@@ -427,29 +427,22 @@ struct rrd_database *get_outdated_db(struct rrd_database **dblist)
  */
 int get_next_update(struct rrd_database **dblist, const char **name)
 {
-       int i, sleeptime = 0, diff;
+       int i, sleeptime = -1, diff;
        time_t now = time(0);
 
        for (i = 0; dblist[i]; i++) {
+               if (dblist[i]->update_active)
+                       continue;
+
                diff = ROUND_UP(dblist[i]->last_update, dblist[i]->interval) - now;
                diff = max(diff, dblist[i]->update_backoff - now);
 
-               if (dblist[i]->update_active)
-                       diff = (now + dblist[i]->interval) % dblist[i]->interval;
-
-               if (!sleeptime) {
-                       sleeptime = diff;
-                       *name = dblist[i]->name;
-               }
-               if (sleeptime > diff) {
+               if (sleeptime == -1 || sleeptime > diff) {
                        sleeptime = diff;
                        *name = dblist[i]->name;
                }
        }
 
-       if (sleeptime == 0)
-               sleeptime = -1;
-
        return sleeptime;
 }