X-Git-Url: https://git.octo.it/?p=rrdtool.git;a=blobdiff_plain;f=src%2Frrd_create.c;h=52a099b3cc73b55fc0bd36228f04e8631cebee82;hp=3b57c9f4d270f71ff37a3547d7fe99ea749781f9;hb=56d67cdd0c5b2c27c9242a3d5810c7184917f663;hpb=9e6dd6a7c7768d90a8f62d7379d3dfa361e3ad7f diff --git a/src/rrd_create.c b/src/rrd_create.c index 3b57c9f..52a099b 100644 --- a/src/rrd_create.c +++ b/src/rrd_create.c @@ -1,5 +1,5 @@ /***************************************************************************** - * RRDtool 1.3.2 Copyright by Tobi Oetiker, 1997-2008 + * RRDtool 1.4.0 Copyright by Tobi Oetiker, 1997-2009 ***************************************************************************** * rrd_create.c creates new rrds *****************************************************************************/ @@ -14,6 +14,10 @@ #include "rrd_is_thread_safe.h" +#ifdef WIN32 +# include +#endif + unsigned long FnvHash( const char *str); int create_hw_contingent_rras( @@ -124,14 +128,14 @@ int rrd_create_r( /* init rrd clean */ rrd_init(&rrd); /* static header */ - if ((rrd.stat_head = calloc(1, sizeof(stat_head_t))) == NULL) { + if ((rrd.stat_head = (stat_head_t*)calloc(1, sizeof(stat_head_t))) == NULL) { rrd_set_error("allocating rrd.stat_head"); rrd_free2(&rrd); return (-1); } /* live header */ - if ((rrd.live_head = calloc(1, sizeof(live_head_t))) == NULL) { + if ((rrd.live_head = (live_head_t*)calloc(1, sizeof(live_head_t))) == NULL) { rrd_set_error("allocating rrd.live_head"); rrd_free2(&rrd); return (-1); @@ -162,7 +166,7 @@ int rrd_create_r( if (strncmp(argv[i], "DS:", 3) == 0) { size_t old_size = sizeof(ds_def_t) * (rrd.stat_head->ds_cnt); - if ((rrd.ds_def = rrd_realloc(rrd.ds_def, + if ((rrd.ds_def = (ds_def_t*)rrd_realloc(rrd.ds_def, old_size + sizeof(ds_def_t))) == NULL) { rrd_set_error("allocating rrd.ds_def"); @@ -227,11 +231,11 @@ int rrd_create_r( rrd.stat_head->ds_cnt++; } else if (strncmp(argv[i], "RRA:", 4) == 0) { char *argvcopy; - char *tokptr; + char *tokptr = ""; size_t old_size = sizeof(rra_def_t) * (rrd.stat_head->rra_cnt); int row_cnt; - if ((rrd.rra_def = rrd_realloc(rrd.rra_def, + if ((rrd.rra_def = (rra_def_t*)rrd_realloc(rrd.rra_def, old_size + sizeof(rra_def_t))) == NULL) { rrd_set_error("allocating rrd.rra_def"); @@ -606,7 +610,7 @@ int create_hw_contingent_rras( (rrd->stat_head->rra_cnt)++; /* allocate the memory for the 4 contingent RRAs */ old_size = sizeof(rra_def_t) * (rrd->stat_head->rra_cnt); - if ((rrd->rra_def = rrd_realloc(rrd->rra_def, + if ((rrd->rra_def = (rra_def_t*)rrd_realloc(rrd->rra_def, old_size + 4 * sizeof(rra_def_t))) == NULL) { rrd_free2(rrd); @@ -675,6 +679,10 @@ int rrd_create_fn( rrd_t rrd_dn; unsigned rrd_flags = RRD_READWRITE | RRD_CREAT; + unkn_cnt = 0; + for (i = 0; i < rrd->stat_head->rra_cnt; i++) + unkn_cnt += rrd->stat_head->ds_cnt * rrd->rra_def[i].row_cnt; + if ((rrd_file_dn = rrd_open(file_name, rrd, rrd_flags)) == NULL) { rrd_set_error("creating '%s': %s", file_name, rrd_strerror(errno)); rrd_free2(rrd); @@ -690,7 +698,7 @@ int rrd_create_fn( rrd_write(rrd_file_dn, rrd->live_head, sizeof(live_head_t)); - if ((rrd->pdp_prep = calloc(1, sizeof(pdp_prep_t))) == NULL) { + if ((rrd->pdp_prep = (pdp_prep_t*)calloc(1, sizeof(pdp_prep_t))) == NULL) { rrd_set_error("allocating pdp_prep"); rrd_free2(rrd); rrd_close(rrd_file_dn); @@ -706,7 +714,7 @@ int rrd_create_fn( for (i = 0; i < rrd->stat_head->ds_cnt; i++) rrd_write(rrd_file_dn, rrd->pdp_prep, sizeof(pdp_prep_t)); - if ((rrd->cdp_prep = calloc(1, sizeof(cdp_prep_t))) == NULL) { + if ((rrd->cdp_prep = (cdp_prep_t*)calloc(1, sizeof(cdp_prep_t))) == NULL) { rrd_set_error("allocating cdp_prep"); rrd_free2(rrd); rrd_close(rrd_file_dn); @@ -753,7 +761,7 @@ int rrd_create_fn( /* now, we must make sure that the rest of the rrd struct is properly initialized */ - if ((rrd->rra_ptr = calloc(1, sizeof(rra_ptr_t))) == NULL) { + if ((rrd->rra_ptr = (rra_ptr_t*)calloc(1, sizeof(rra_ptr_t))) == NULL) { rrd_set_error("allocating rra_ptr"); rrd_free2(rrd); rrd_close(rrd_file_dn); @@ -779,10 +787,6 @@ int rrd_create_fn( for (i = 0; i < 512; ++i) unknown[i] = DNAN; - unkn_cnt = 0; - for (i = 0; i < rrd->stat_head->rra_cnt; i++) - unkn_cnt += rrd->stat_head->ds_cnt * rrd->rra_def[i].row_cnt; - while (unkn_cnt > 0) { if(rrd_write(rrd_file_dn, unknown, sizeof(rrd_value_t) * min(unkn_cnt, 512)) < 0) { @@ -799,6 +803,7 @@ int rrd_create_fn( return -1; } /* flush all we don't need out of the cache */ + rrd_init(&rrd_dn); if((rrd_file_dn = rrd_open(file_name, &rrd_dn, RRD_READONLY)) != NULL) { rrd_dontneed(rrd_file_dn, &rrd_dn);