]> git.itanic.dy.fi Git - rrdd/blobdiff - rrdtool.c
rrdtool: queue post_draw_cmd to be after images
[rrdd] / rrdtool.c
index 0651e45e0a83dd6f0a81e4b9d1ed4e7954686b01..d7b710b709435d474dd1343402f99c2ee40779f3 100644 (file)
--- a/rrdtool.c
+++ b/rrdtool.c
@@ -250,6 +250,16 @@ static int write_to_logfile(struct rrd_database *rrd, const char *data)
        return ret < 0 ? ret : 0;
 }
 
+static int run_post_draw_cmd(struct rrd_database *rrd)
+{
+       pr_info("Running post draw command for %s\n", rrd->name);
+
+       if (rrd->post_draw_cmd && !strcmp(rrd->post_draw_cmd[0], "shell"))
+               run(rrd->post_draw_cmd[1], &rrd->post_draw_cmd[1]);
+
+       return 0;
+}
+
 static int do_rrdtool_update_data(struct rrd_database *rrd)
 {
        char data[RRD_DATA_MAX_LEN + 3]; /* 3 == "N:" + NULL termination */
@@ -286,8 +296,18 @@ static int do_rrdtool_update_data(struct rrd_database *rrd)
        if (rrd->images)
                rrdtool_draw_images(rrd->images);
 
-       if (rrd->post_draw_cmd && !strcmp(rrd->post_draw_cmd[0], "shell"))
-               run(rrd->post_draw_cmd[1], &rrd->post_draw_cmd[1]);
+       /*
+        * We rely on the fact that rrdtool_draw_images queues image
+        * drawings into low priority queue and the post draw queue is
+        * placed on the queue after images. This ensures post draw
+        * command is not started before images are started.
+        *
+        * There is nothing that guarantees post_draw_cmd is executed
+        * after all images are completed though, but it's close..
+        */
+       if (rrd->post_draw_cmd)
+               queue_work(WORK_PRIORITY_LOW, "rrdtool_post_draw_cmd",
+                       (work_fn_t *)run_post_draw_cmd, rrd);
 
        return 0;
 }