From 4a3a22e8bf152661db7ab1028792529b87082bcb Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Sat, 21 Nov 2020 11:41:00 +0200 Subject: [PATCH] rrtdool: Simplify sleeptime calculation The code can be refactored into understandable form with less lines. Signed-off-by: Timo Kokkonen --- rrdtool.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/rrdtool.c b/rrdtool.c index df18950..f570f5c 100644 --- 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; } -- 2.45.0