(filename, cf_idx, start, end, step, ds_cnt, ds_namv, data));
} /* int rrd_fetch_r */
+int rrd_fetch_empty(
+ time_t *start,
+ time_t *end, /* which time frame do you want ? */
+ unsigned long *step, /* which stepsize do you want? */
+ unsigned long *ds_cnt, /* number of data sources in file */
+ char *ds_nam, /* wanted data source */
+ char ***ds_namv, /* names of data_sources */
+ rrd_value_t **data)
+{
+ unsigned long rows;
+
+ if (((*ds_namv) =
+ (char **) malloc(sizeof(char *))) == NULL) {
+ rrd_set_error("malloc fetch ds_namv array");
+ return (-1);
+ }
+ if ((((*ds_namv)[0]) = (char*)strdup(ds_nam)) == NULL) {
+ rrd_set_error("malloc fetch ds_namv entry");
+ free(*ds_namv);
+ return (-1);
+ }
+
+ *ds_cnt = 1;
+ if (*step == 0) *step = (*end - *start) / 100;
+ *start -= (*start % *step);
+ *end += (*step - *end % *step);
+ rows = (*end - *start) / *step + 1;
+
+ if (((*data) = (rrd_value_t*)malloc(rows * sizeof(rrd_value_t))) == NULL) {
+ rrd_set_error("malloc fetch data area");
+ free((*ds_namv)[0]);
+ free(*ds_namv);
+ return (-1);
+ }
+
+ while (--rows)
+ (*data)[rows-1] = DNAN;
+ return (0);
+}
+
int rrd_fetch_fn(
const char *filename, /* name of the rrd */
enum cf_en cf_idx, /* which consolidation function ? */
if (status != 0) {
if (im->extra_flags & ALLOW_MISSING_DS) {
rrd_clear_error();
- im->gdes[i].ds_cnt = im->gdes[i].start = im->gdes[i].end = 0;
- ft_step = 1;
+ if (rrd_fetch_empty(&im->gdes[i].start,
+ &im->gdes[i].end,
+ &ft_step,
+ &im->gdes[i].ds_cnt,
+ im->gdes[i].ds_nam,
+ &im->gdes[i].ds_namv,
+ &im->gdes[i].data) == -1)
+ return -1;
} else return (status);
}
}
if (im->extra_flags & ALLOW_MISSING_DS) {
/* Unable to fetch data, assume fake data */
rrd_clear_error();
- im->gdes[i].ds_cnt = im->gdes[i].start = im->gdes[i].end = 0;
- ft_step = 1;
+ if (rrd_fetch_empty(&im->gdes[i].start,
+ &im->gdes[i].end,
+ &ft_step,
+ &im->gdes[i].ds_cnt,
+ im->gdes[i].ds_nam,
+ &im->gdes[i].ds_namv,
+ &im->gdes[i].data) == -1)
+ return -1;
} else return -1;
}
}
im->gdes[i].ds = ii;
}
}
- if ((im->gdes[i].ds == -1) &&
- !(im->extra_flags & ALLOW_MISSING_DS)) {
+ if (im->gdes[i].ds == -1) {
rrd_set_error("No DS called '%s' in '%s'",
im->gdes[i].ds_nam, im->gdes[i].rrd);
return -1;