From 8a21b9cb276aa9b7401533474019f4ee1251a377 Mon Sep 17 00:00:00 2001 From: oetiker Date: Fri, 25 May 2007 13:14:35 +0000 Subject: [PATCH] updates from Bernhard Fischer rep dot nop gmail com - add some more rrd_sterror calls to failure paths. - make rrdtool updatev work like 1.2.23 (i.e. multiple values are still broken, but at least updating a single value works; see http://oss.oetiker.ch/rrdtool-trac/ticket/8) - indent touched files. git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@1085 a5681a0c-68f1-0310-ab6d-d61299d08faa --- src/rrd_dump.c | 2 +- src/rrd_fetch.c | 10 ++++------ src/rrd_open.c | 22 ++++++++++------------ src/rrd_resize.c | 2 +- src/rrd_update.c | 19 +++++-------------- 5 files changed, 21 insertions(+), 34 deletions(-) diff --git a/src/rrd_dump.c b/src/rrd_dump.c index 3b2a025..0b93103 100644 --- a/src/rrd_dump.c +++ b/src/rrd_dump.c @@ -83,7 +83,7 @@ int rrd_dump_r( rrd_value_t value; struct tm tm; - rrd_file = rrd_open(filename, &rrd, RRD_READONLY|RRD_READAHEAD); + rrd_file = rrd_open(filename, &rrd, RRD_READONLY | RRD_READAHEAD); if (rrd_file == NULL) { rrd_free(&rrd); return (-1); diff --git a/src/rrd_fetch.c b/src/rrd_fetch.c index 866bf97..87c3cd6 100644 --- a/src/rrd_fetch.c +++ b/src/rrd_fetch.c @@ -378,10 +378,9 @@ int rrd_fetch_fn( else rra_pointer = rrd.rra_ptr[chosen_rra].cur_row + 1 + start_offset; - if (rrd_seek(rrd_file, (rra_base - + (rra_pointer - * (*ds_cnt) - * sizeof(rrd_value_t))), SEEK_SET) != 0) { + if (rrd_seek(rrd_file, (rra_base + (rra_pointer * (*ds_cnt) + * sizeof(rrd_value_t))), + SEEK_SET) != 0) { rrd_set_error("seek error in RRA"); for (i = 0; (unsigned) i < *ds_cnt; i++) free((*ds_namv)[i]); @@ -429,8 +428,7 @@ int rrd_fetch_fn( * be wrapped*/ if (rra_pointer >= (signed) rrd.rra_def[chosen_rra].row_cnt) { rra_pointer -= rrd.rra_def[chosen_rra].row_cnt; - if (rrd_seek(rrd_file, (rra_base + rra_pointer - * (*ds_cnt) + if (rrd_seek(rrd_file, (rra_base + rra_pointer * (*ds_cnt) * sizeof(rrd_value_t)), SEEK_SET) != 0) { rrd_set_error("wrap seek in RRA did fail"); diff --git a/src/rrd_open.c b/src/rrd_open.c index 07ee109..baeb003 100644 --- a/src/rrd_open.c +++ b/src/rrd_open.c @@ -302,13 +302,16 @@ rrd_file_t *rrd_open( int rrd_close( rrd_file_t *rrd_file) { - int ret = 0; + int ret; #ifdef HAVE_MMAP ret = munmap(rrd_file->file_start, rrd_file->file_len); -// if (ret != 0) -// rrd_set_error("munmap rrd_file"); + if (ret != 0) + rrd_set_error("munmap rrd_file: %s", rrd_strerror(errno)); #endif + ret = close(rrd_file->fd); + if (ret != 0) + rrd_set_error("closing file: %s", rrd_strerror(errno)); free(rrd_file); rrd_file = NULL; return ret; @@ -377,18 +380,12 @@ ssize_t rrd_write( const void *buf, size_t count) { - ssize_t ret = count; - #ifdef HAVE_MMAP - char *off, *new_pos; - - off = rrd_file->file_start + rrd_file->pos; - new_pos = memmove(rrd_file->file_start + rrd_file->pos, buf, count); - ret = new_pos - off; + memmove(rrd_file->file_start + rrd_file->pos, buf, count); + return count; /* mimmic write() semantics */ #else - ret = write(rrd_file->fd, buf, count); + return write(rrd_file->fd, buf, count); #endif - return ret; } /* flush all data pending to be written to FD. */ @@ -427,6 +424,7 @@ void rrd_free( free(rrd->pdp_prep); free(rrd->cdp_prep); free(rrd->rrd_value); +//XXX: ? rrd_init(rrd); #endif } diff --git a/src/rrd_resize.c b/src/rrd_resize.c index e29f2dd..f64615c 100644 --- a/src/rrd_resize.c +++ b/src/rrd_resize.c @@ -82,7 +82,7 @@ int rrd_resize( return (-1); } - rrd_out_file = rrd_open(outfilename, &rrdnew, RRD_READWRITE|RRD_CREAT); + rrd_out_file = rrd_open(outfilename, &rrdnew, RRD_READWRITE | RRD_CREAT); if (rrd_out_file == NULL) { rrd_set_error("Can't create '%s': %s", outfilename, rrd_strerror(errno)); diff --git a/src/rrd_update.c b/src/rrd_update.c index 7890f28..eb08f78 100644 --- a/src/rrd_update.c +++ b/src/rrd_update.c @@ -105,7 +105,7 @@ static info_t *write_RRA_row( (rrd_file, &(rrd->cdp_prep[cdp_idx].scratch[CDP_scratch_idx].u_val), sizeof(rrd_value_t) * 1) != sizeof(rrd_value_t) * 1) { - rrd_set_error("writing rrd"); + rrd_set_error("writing rrd: %s", rrd_strerror(errno)); return 0; } *rra_current += sizeof(rrd_value_t); @@ -1458,10 +1458,12 @@ int _rrd_update( free(rra_step_cnt); rpnstack_free(&rpnstack); -#ifdef HAVE_MMAP +#if 0 //def HAVE_MMAP if (munmap(rrd_file->file_start, rrd_file->file_len) == -1) { rrd_set_error("error writing(unmapping) file: %s", filename); } +#else + rrd_flush(rrd_file); //XXX: really needed? #endif /* if we got here and if there is an error and if the file has not been * written to, then close things up and return. */ @@ -1609,20 +1611,9 @@ int _rrd_update( return (-1); } #endif - close(rrd_file->fd); - } - - /* OK now close the files and free the memory */ - if (close(rrd_file->fd) != 0) { - rrd_set_error("closing rrd"); - free(updvals); - free(tmpl_idx); - rrd_free(&rrd); - free(pdp_temp); - free(pdp_new); - return (-1); } + rrd_close(rrd_file); rrd_free(&rrd); free(updvals); free(tmpl_idx); -- 2.30.2