time_t start_tmp = 0, end_tmp = 0;
const char *cf;
char *daemon = NULL;
+ int status;
rrd_time_value_t start_tv, end_tv;
char *parsetime_error = NULL;
break;
case 'd':
- if (daemon != NULL)
- free (daemon);
+ if (daemon != NULL)
+ free (daemon);
daemon = strdup (optarg);
if (daemon == NULL)
{
if (daemon == NULL)
{
rrd_set_error("strdup failed.");
- return (-1);
+ return (-1);
}
}
}
+ if (daemon != NULL)
+ {
+ status = rrdc_connect (daemon);
+ if (status != 0)
+ {
+ rrd_set_error ("rrdc_connect failed with status %i.", status);
+ return (-1);
+ }
+
+ status = rrdc_flush (argv[optind]);
+ if (status != 0)
+ {
+ rrd_set_error ("rrdc_flush (%s) failed with status %i.",
+ argv[optind], status);
+ return (-1);
+ }
+
+ rrdc_disconnect ();
+ } /* if (daemon) */
+
cf = argv[optind + 1];
- if (rrd_fetch_r(argv[optind], cf, start, end, step, daemon, ds_cnt,
- ds_namv, data) != 0)
+ status = rrd_fetch_r(argv[optind], cf, start, end, step,
+ ds_cnt, ds_namv, data);
+ if (status != 0)
return (-1);
return (0);
}
* will be changed to represent reality */
unsigned long *step, /* which stepsize do you want?
* will be changed to represent reality */
- const char *daemon,
unsigned long *ds_cnt, /* number of data sources in file */
char ***ds_namv, /* names of data_sources */
rrd_value_t **data)
{ /* two dimensional array containing the data */
enum cf_en cf_idx;
- int status;
if ((int) (cf_idx = cf_conv(cf)) == -1) {
return -1;
}
- if (daemon != NULL)
- {
- status = rrdc_connect (daemon);
- if (status != 0)
- {
- rrd_set_error ("rrdc_connect failed with status %i.", status);
- return (-1);
- }
- }
-
- status = rrd_fetch_fn (filename, cf_idx, start, end, step,
- (daemon == NULL) ? 0 : 1,
- ds_cnt, ds_namv, data);
-
- rrdc_disconnect ();
-
- return (status);
+ return (rrd_fetch_fn
+ (filename, cf_idx, start, end, step, ds_cnt, ds_namv, data));
} /* int rrd_fetch_r */
int rrd_fetch_fn(
* will be changed to represent reality */
unsigned long *step, /* which stepsize do you want?
* will be changed to represent reality */
- int use_rrdcached,
unsigned long *ds_cnt, /* number of data sources in file */
char ***ds_namv, /* names of data_sources */
rrd_value_t **data)
rrd_value_t *data_ptr;
unsigned long rows;
- if (use_rrdcached)
- {
- int status;
-
- status = rrdc_flush (filename);
- if (status != 0)
- {
- rrd_set_error ("rrdc_flush failed with status %i.", status);
- return (-1);
- }
- }
-
#ifdef DEBUG
fprintf(stderr, "Entered rrd_fetch_fn() searching for the best match\n");
fprintf(stderr, "Looking for: start %10lu end %10lu step %5lu\n",
if (!skip) {
unsigned long ft_step = im->gdes[i].step; /* ft_step will record what we got from fetch */
+ /* Flush the file if
+ * - a connection to the daemon has been established
+ * - this is the first occurrence of that RRD file
+ */
+ if (im->use_rrdcached)
+ {
+ int status;
+
+ status = 0;
+ for (ii = 0; ii < i; ii++)
+ {
+ if (strcmp (im->gdes[i].rrd, im->gdes[ii].rrd) == 0)
+ {
+ status = 1;
+ break;
+ }
+ }
+
+ if (status == 0)
+ {
+ status = rrdc_flush (im->gdes[i].rrd);
+ if (status != 0)
+ {
+ rrd_set_error ("rrdc_flush (%s) failed with status %i.",
+ im->gdes[i].rrd, status);
+ return (-1);
+ }
+ }
+ } /* if (im->use_rrdcached) */
+
if ((rrd_fetch_fn(im->gdes[i].rrd,
im->gdes[i].cf,
&im->gdes[i].start,
&im->gdes[i].end,
&ft_step,
- im->use_rrdcached ? 1 : 0,
&im->gdes[i].ds_cnt,
&im->gdes[i].ds_namv,
&im->gdes[i].data)) == -1) {