X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Frrd_fetch.c;h=563e76b3c05973509630084b7b812dddf0f7034c;hb=8fdbf4660969f9bde7f0f434f2d1002028d36814;hp=c745f06160091d7c7187aa7129ef6289e6a9c02f;hpb=6d19d9d651c2b710f26ba98417f280d1b6cd9cf4;p=rrdtool.git diff --git a/src/rrd_fetch.c b/src/rrd_fetch.c index c745f06..563e76b 100644 --- a/src/rrd_fetch.c +++ b/src/rrd_fetch.c @@ -1,5 +1,5 @@ /***************************************************************************** - * RRDtool 1.3.0 Copyright by Tobi Oetiker, 1997-2008 + * RRDtool 1.3.2 Copyright by Tobi Oetiker, 1997-2008 ***************************************************************************** * rrd_fetch.c read date from an rrd to use for further processing ***************************************************************************** @@ -73,7 +73,8 @@ int rrd_fetch( long step_tmp = 1; time_t start_tmp = 0, end_tmp = 0; const char *cf; - char *daemon = NULL; + char *opt_daemon = NULL; + int status; rrd_time_value_t start_tv, end_tv; char *parsetime_error = NULL; @@ -119,10 +120,10 @@ int rrd_fetch( break; case 'd': - if (daemon != NULL) - free (daemon); - daemon = strdup (optarg); - if (daemon == NULL) + if (opt_daemon != NULL) + free (opt_daemon); + opt_daemon = strdup (optarg); + if (opt_daemon == NULL) { rrd_set_error ("strdup failed."); return (-1); @@ -166,10 +167,47 @@ int rrd_fetch( return -1; } + if (opt_daemon == NULL) + { + char *temp; + + temp = getenv (ENV_RRDCACHED_ADDRESS); + if (temp != NULL) + { + opt_daemon = strdup (temp); + if (opt_daemon == NULL) + { + rrd_set_error("strdup failed."); + return (-1); + } + } + } + + if (opt_daemon != NULL) + { + status = rrdc_connect (opt_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 (opt_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); } @@ -182,35 +220,18 @@ int rrd_fetch_r( * 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( @@ -221,7 +242,6 @@ 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) @@ -241,18 +261,6 @@ int rrd_fetch_fn( 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",