X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Frrd_create.c;h=6dfc0fa6956c9b965ee6376fe37f87c4446324ed;hb=eb3f17d3211772519c721d7f6bc8b6e5d880a29b;hp=a8f6a2967fb1abaf8740e1559008b7a191f3b739;hpb=3d99d8360586a320cb4e349c0a3c5c2f13b4169c;p=rrdtool.git diff --git a/src/rrd_create.c b/src/rrd_create.c index a8f6a29..6dfc0fa 100644 --- a/src/rrd_create.c +++ b/src/rrd_create.c @@ -4,6 +4,8 @@ * rrd_create.c creates new rrds *****************************************************************************/ +#include +#include #include #include "rrd_tool.h" @@ -22,6 +24,8 @@ void parseGENERIC_DS( const char *def, rrd_t *rrd, int ds_idx); +long int rra_random_row( + rra_def_t *); int rrd_create( int argc, @@ -690,13 +694,13 @@ int rrd_create_fn( if ((rrd->pdp_prep = calloc(1, sizeof(pdp_prep_t))) == NULL) { rrd_set_error("allocating pdp_prep"); - free(rrd->stat_head); - free(rrd->live_head); + free(rrd->stat_head); + free(rrd->live_head); close(rrd_file); return (-1); } - strcpy(rrd->pdp_prep->last_ds, "UNKN"); + strcpy(rrd->pdp_prep->last_ds, "U"); rrd->pdp_prep->scratch[PDP_val].u_val = 0.0; rrd->pdp_prep->scratch[PDP_unkn_sec_cnt].u_cnt = @@ -707,8 +711,8 @@ int rrd_create_fn( if ((rrd->cdp_prep = calloc(1, sizeof(cdp_prep_t))) == NULL) { rrd_set_error("allocating cdp_prep"); - free(rrd->stat_head); - free(rrd->live_head); + free(rrd->stat_head); + free(rrd->live_head); close(rrd_file); return (-1); } @@ -755,8 +759,8 @@ int rrd_create_fn( if ((rrd->rra_ptr = calloc(1, sizeof(rra_ptr_t))) == NULL) { rrd_set_error("allocating rra_ptr"); - free(rrd->stat_head); - free(rrd->live_head); + free(rrd->stat_head); + free(rrd->live_head); close(rrd_file); return (-1); } @@ -766,15 +770,15 @@ int rrd_create_fn( * would occur for cur_row = 1 because rrd_update increments * the pointer a priori. */ for (i = 0; i < rrd->stat_head->rra_cnt; i++) { - rrd->rra_ptr->cur_row = rrd->rra_def[i].row_cnt - 1; + rrd->rra_ptr->cur_row = rra_random_row(&rrd->rra_def[i]); write(rrd_file, rrd->rra_ptr, sizeof(rra_ptr_t)); } /* write the empty data area */ if ((unknown = (rrd_value_t *) malloc(512 * sizeof(rrd_value_t))) == NULL) { rrd_set_error("allocating unknown"); - free(rrd->stat_head); - free(rrd->live_head); + free(rrd->stat_head); + free(rrd->live_head); close(rrd_file); return (-1); } @@ -792,8 +796,8 @@ int rrd_create_fn( } free(unknown); fdatasync(rrd_file); - free(rrd->stat_head); - free(rrd->live_head); + free(rrd->stat_head); + free(rrd->live_head); if (close(rrd_file) == -1) { rrd_set_error("creating rrd: %s", rrd_strerror(errno)); return -1; @@ -805,3 +809,16 @@ int rrd_create_fn( rrd_close(rrd_file_dn); return (0); } + +static int rand_init = 0; + +long int rra_random_row( + rra_def_t *rra) +{ + if (!rand_init) { + srandom((unsigned int) time(NULL) + (unsigned int) getpid()); + rand_init++; + } + + return random() % rra->row_cnt; +}