X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Frrd_lastupdate.c;h=33cd944793bf3293ffe5d8969b0cfcf7300523fd;hb=daf8e7ff715a59e1f9827080d1b785ffb3c5a4b1;hp=169c49dc69c727e9c26b2cfd359dbffe3e908061;hpb=5fc7ff89bdbced9c593c566fea9840a269935dcd;p=rrdtool.git diff --git a/src/rrd_lastupdate.c b/src/rrd_lastupdate.c index 169c49d..33cd944 100644 --- a/src/rrd_lastupdate.c +++ b/src/rrd_lastupdate.c @@ -1,5 +1,5 @@ /***************************************************************************** - * RRDtool 1.2.23 Copyright by Tobi Oetiker, 1997-2007 + * RRDtool 1.3rc7 Copyright by Tobi Oetiker, 1997-2008 ***************************************************************************** * rrd_lastupdate Get the last datum entered for each DS *****************************************************************************/ @@ -8,47 +8,58 @@ #include "rrd_rpncalc.h" #include -int -rrd_lastupdate(int argc, char **argv, time_t *last_update, - unsigned long *ds_cnt, char ***ds_namv, char ***last_ds) { - unsigned long i=0; - char *filename; - FILE *in_file; - rrd_t rrd; +int rrd_lastupdate( + int argc, + char **argv, + time_t *last_update, + unsigned long *ds_cnt, + char ***ds_namv, + char ***last_ds) +{ + unsigned long i = 0; + char *filename; + rrd_t rrd; + rrd_file_t *rrd_file; - if(argc < 2){ + if (argc < 2) { rrd_set_error("please specify an rrd"); - return -1; + goto err_out; } filename = argv[1]; - if(rrd_open(filename,&in_file,&rrd, RRD_READONLY)==-1){ - return(-1); - } - fclose(in_file); + rrd_file = rrd_open(filename, &rrd, RRD_READONLY); + if (rrd_file == NULL) + goto err_free; - *last_update=rrd.live_head->last_up; + *last_update = rrd.live_head->last_up; *ds_cnt = rrd.stat_head->ds_cnt; if (((*ds_namv) = - (char **) malloc(rrd.stat_head->ds_cnt * sizeof(char*)))==NULL){ + (char **) malloc(rrd.stat_head->ds_cnt * sizeof(char *))) == NULL) { rrd_set_error("malloc fetch ds_namv array"); - rrd_free(&rrd); - return(-1); - } + goto err_close; + } if (((*last_ds) = - (char **) malloc(rrd.stat_head->ds_cnt * sizeof(char*)))==NULL){ + (char **) malloc(rrd.stat_head->ds_cnt * sizeof(char *))) == NULL) { rrd_set_error("malloc fetch last_ds array"); - rrd_free(&rrd); - free(*ds_namv); - return(-1); - } - - for(i=0;ids_cnt;i++){ - (*ds_namv)[i] = sprintf_alloc("%s", rrd.ds_def[i].ds_nam); - (*last_ds)[i] = sprintf_alloc("%s", rrd.pdp_prep[i].last_ds); + goto err_free_ds_namv; + } + + for (i = 0; i < rrd.stat_head->ds_cnt; i++) { + (*ds_namv)[i] = sprintf_alloc("%s", rrd.ds_def[i].ds_nam); + (*last_ds)[i] = sprintf_alloc("%s", rrd.pdp_prep[i].last_ds); } rrd_free(&rrd); - return(0); + rrd_close(rrd_file); + return (0); + + err_free_ds_namv: + free(*ds_namv); + err_close: + rrd_close(rrd_file); + err_free: + rrd_free(&rrd); + err_out: + return (-1); }