X-Git-Url: https://git.octo.it/?p=rrdtool.git;a=blobdiff_plain;f=src%2Frrd_lastupdate.c;h=79274b55c929c727e27cd5d381b507498618fcd9;hp=abba2773dab3139d00fd4abd5d98071194f764b9;hb=009ac7ac9dde1ba7c450b230b9118cff2cedc9f6;hpb=818549a636c390fb4a8390a7e2195a52293cd56b diff --git a/src/rrd_lastupdate.c b/src/rrd_lastupdate.c index abba277..79274b5 100644 --- a/src/rrd_lastupdate.c +++ b/src/rrd_lastupdate.c @@ -8,15 +8,20 @@ #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; - rrd_t rrd; - rrd_file_t* rrd_file; - - if(argc < 2){ +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) { rrd_set_error("please specify an rrd"); return -1; } @@ -24,31 +29,32 @@ rrd_lastupdate(int argc, char **argv, time_t *last_update, rrd_file = rrd_open(filename, &rrd, RRD_READONLY); if (rrd_file == NULL) - return(-1); + return (-1); - *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); - } + rrd_free(&rrd); + return (-1); + } 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); + rrd_free(&rrd); + free(*ds_namv); + return (-1); + } + + 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); + close(rrd_file->fd); rrd_close(rrd_file); - return(0); + return (0); }