int rrdtool_draw_image(struct rrd_image *image)
{
- int pid;
char cmd[] = RRDTOOL_CMD;
// char cmd[] = "echo";
char *args[512], argstr[ARGSTR_LEN];
pr_info("Drawing image %s\n", image->image_filename);
tmpfile[0] = 0;
- strncat(tmpfile, image->image_filename, sizeof(tmp) - strlen(tmp) - 1);
- strncat(tmpfile, ".tmp", sizeof(tmp) - strlen(tmp) - 1);
+ strncat(tmpfile, image->image_filename, sizeof(tmp) - 1);
+ strncat(tmpfile, ".tmp", sizeof(tmp) - 1);
if (image->updatestr)
updatestr = image->updatestr;
add_arg(args, argcnt, argstr, idx, "COMMENT: %s\\c", timestamp);
- pid = run(cmd, args);
- harvest_zombies(pid);
+ run(cmd, args);
rename(tmpfile, image->image_filename);
int i;
for (i = 0; image[i]; i++)
queue_work(WORK_PRIORITY_LOW, "rrdtool_draw_image",
- rrdtool_draw_image, image[i]);
+ (work_fn_t *)rrdtool_draw_image, image[i]);
return 0;
}
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)
{
- int pid;
char data[RRD_DATA_MAX_LEN + 3]; /* 3 == "N:" + NULL termination */
char cmd[] = RRDTOOL_CMD;
// char cmd[] = "echo";
};
int l;
+ bzero(data, sizeof(data));
l = sprintf(data, "N:");
if (rrd->parser && rrd->parser->parse) {
- rrd->parser->parse(data + l, rrd->parser_data);
+ rrd->parser->parse(data + l, rrd->parser_data,
+ &rrd->parser_state);
data[RRD_DATA_MAX_LEN + 2] = '\0';
pr_info("Data: %s\n", data);
sanitize_rrd_update_data(data + l);
write_to_logfile(rrd, data);
- pid = run(cmd, cmdline);
- harvest_zombies(pid);
+ run(cmd, cmdline);
}
if (rrd->pre_draw_cmd && !strcmp(rrd->pre_draw_cmd[0], "shell")) {
- pid = run(rrd->pre_draw_cmd[1], &rrd->pre_draw_cmd[1]);
- harvest_zombies(pid);
+ run(rrd->pre_draw_cmd[1], &rrd->pre_draw_cmd[1]);
}
if (rrd->images)
rrdtool_draw_images(rrd->images);
+ /*
+ * 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;
}
rrd->last_update = time(0);
return queue_work(WORK_PRIORITY_HIGH, "rrdtool_update_data",
- do_rrdtool_update_data, rrd);
+ (work_fn_t *)do_rrdtool_update_data, rrd);
}
/*
// char cmd[] = "echo";
char *args[512], argstr[ARGSTR_LEN];
int idx = 0, argcnt = 0;
- int child, i;
+ int i;
if (!db->filename) {
pr_err("Database %s missing database filename\n", db->name);
db->archives[i].rows);
}
- child = run(cmd, args);
-
- harvest_zombies(child);
+ run(cmd, args);
return 0;
}