]> git.itanic.dy.fi Git - rrdd/blobdiff - rrdtool.c
onewire_parser.c: Fix compiler warnings about string lengths
[rrdd] / rrdtool.c
index ece5d12d7d5485954ab779b326d874fc2a79c6d4..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;
 }
 
@@ -470,14 +463,14 @@ static int get_last_update(struct rrd_database *db)
        char *args[10], argstr[ARGSTR_LEN];
        char buf[16];
        int idx = 0, argcnt = 0;
-       int ofd, efd, child;
+       int ofd, child;
        int ret;
 
        add_arg(args, argcnt, argstr, idx, RRDTOOL_CMD);
        add_arg(args, argcnt, argstr, idx, "last");
        add_arg(args, argcnt, argstr, idx, db->filename);
 
-       child = run_piped(cmd, args, NULL, &ofd, &efd);
+       child = run_piped(cmd, args, NULL, &ofd, NULL);
        ret = read(ofd, buf, sizeof(buf) - 1);
        if (ret < 0) {
                pr_err("Error reading: %m\n");
@@ -490,6 +483,7 @@ static int get_last_update(struct rrd_database *db)
        pr_info("Last update for %s is: %ld, %ld sec ago\n", db->name, db->last_update,
                time(NULL) - db->last_update);
 
+       close(ofd);
        clear_zombie(child);
 
        return 0;