projects
/
rrdtool.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
proper fix for the header size problem and its effects on rrd_resize
[rrdtool.git]
/
src
/
rrd_create.c
diff --git
a/src/rrd_create.c
b/src/rrd_create.c
index
fd1ac9e
..
a36b31d
100644
(file)
--- a/
src/rrd_create.c
+++ b/
src/rrd_create.c
@@
-1,5
+1,5
@@
/*****************************************************************************
/*****************************************************************************
- * RRDtool 1.
3.0 Copyright by Tobi Oetiker, 1997-2008
+ * RRDtool 1.
4.3 Copyright by Tobi Oetiker, 1997-2010
*****************************************************************************
* rrd_create.c creates new rrds
*****************************************************************************/
*****************************************************************************
* rrd_create.c creates new rrds
*****************************************************************************/
@@
-11,9
+11,14
@@
#include "rrd_tool.h"
#include "rrd_rpncalc.h"
#include "rrd_hw.h"
#include "rrd_tool.h"
#include "rrd_rpncalc.h"
#include "rrd_hw.h"
+#include "rrd_client.h"
#include "rrd_is_thread_safe.h"
#include "rrd_is_thread_safe.h"
+#ifdef WIN32
+# include <process.h>
+#endif
+
unsigned long FnvHash(
const char *str);
int create_hw_contingent_rras(
unsigned long FnvHash(
const char *str);
int create_hw_contingent_rras(
@@
-24,8
+29,9
@@
void parseGENERIC_DS(
const char *def,
rrd_t *rrd,
int ds_idx);
const char *def,
rrd_t *rrd,
int ds_idx);
-long int rra_random_row(
- rra_def_t *);
+
+static void rrd_free2(
+ rrd_t *rrd); /* our onwn copy, immmune to mmap */
int rrd_create(
int argc,
int rrd_create(
int argc,
@@
-34,6
+40,8
@@
int rrd_create(
struct option long_options[] = {
{"start", required_argument, 0, 'b'},
{"step", required_argument, 0, 's'},
struct option long_options[] = {
{"start", required_argument, 0, 'b'},
{"step", required_argument, 0, 's'},
+ {"daemon", required_argument, 0, 'd'},
+ {"no-overwrite", no_argument, 0, 'O'},
{0, 0, 0, 0}
};
int option_index = 0;
{0, 0, 0, 0}
};
int option_index = 0;
@@
-44,17
+52,30
@@
int rrd_create(
char *parsetime_error = NULL;
long long_tmp;
int rc;
char *parsetime_error = NULL;
long long_tmp;
int rc;
+ char * opt_daemon = NULL;
+ int opt_no_overwrite = 0;
optind = 0;
opterr = 0; /* initialize getopt */
while (1) {
optind = 0;
opterr = 0; /* initialize getopt */
while (1) {
- opt = getopt_long(argc, argv, "
b:s
:", long_options, &option_index);
+ opt = getopt_long(argc, argv, "
Ob:s:d
:", long_options, &option_index);
if (opt == EOF)
break;
switch (opt) {
if (opt == EOF)
break;
switch (opt) {
+ case 'd':
+ if (opt_daemon != NULL)
+ free (opt_daemon);
+ opt_daemon = strdup (optarg);
+ if (opt_daemon == NULL)
+ {
+ rrd_set_error ("strdup failed.");
+ return (-1);
+ }
+ break;
+
case 'b':
if ((parsetime_error = rrd_parsetime(optarg, &last_up_tv))) {
rrd_set_error("start time: %s", parsetime_error);
case 'b':
if ((parsetime_error = rrd_parsetime(optarg, &last_up_tv))) {
rrd_set_error("start time: %s", parsetime_error);
@@
-85,6
+106,10
@@
int rrd_create(
pdp_step = long_tmp;
break;
pdp_step = long_tmp;
break;
+ case 'O':
+ opt_no_overwrite = 1;
+ break;
+
case '?':
if (optopt != 0)
rrd_set_error("unknown option '%c'", optopt);
case '?':
if (optopt != 0)
rrd_set_error("unknown option '%c'", optopt);
@@
-97,14
+122,24
@@
int rrd_create(
rrd_set_error("need name of an rrd file to create");
return -1;
}
rrd_set_error("need name of an rrd file to create");
return -1;
}
- rc = rrd_create_r(argv[optind],
- pdp_step, last_up,
+
+ rrdc_connect (opt_daemon);
+ if (rrdc_is_connected (opt_daemon)) {
+ rc = rrdc_create (argv[optind],
+ pdp_step, last_up, opt_no_overwrite,
argc - optind - 1, (const char **) (argv + optind + 1));
argc - optind - 1, (const char **) (argv + optind + 1));
+ } else {
+ rc = rrd_create_r2(argv[optind],
+ pdp_step, last_up, opt_no_overwrite,
+ argc - optind - 1, (const char **) (argv + optind + 1));
+ }
return rc;
}
/* #define DEBUG */
return rc;
}
/* #define DEBUG */
+/* For backwards compatibility with previous API. Use rrd_create_r2 if you
+ need to have the no_overwrite parameter. */
int rrd_create_r(
const char *filename,
unsigned long pdp_step,
int rrd_create_r(
const char *filename,
unsigned long pdp_step,
@@
-112,6
+147,16
@@
int rrd_create_r(
int argc,
const char **argv)
{
int argc,
const char **argv)
{
+ return rrd_create_r2(filename,pdp_step,last_up,0,argc,argv);
+}
+int rrd_create_r2(
+ const char *filename,
+ unsigned long pdp_step,
+ time_t last_up,
+ int no_overwrite,
+ int argc,
+ const char **argv)
+{
rrd_t rrd;
long i;
int offset;
rrd_t rrd;
long i;
int offset;
@@
-120,20
+165,22
@@
int rrd_create_r(
unsigned short token_idx, error_flag, period = 0;
unsigned long hashed_name;
unsigned short token_idx, error_flag, period = 0;
unsigned long hashed_name;
+ /* clear any previous errors */
+ rrd_clear_error();
+
/* init rrd clean */
rrd_init(&rrd);
/* static header */
/* 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_set_error("allocating rrd.stat_head");
-
free(rrd.stat_hea
d);
+
rrd_free2(&rr
d);
return (-1);
}
/* live header */
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_set_error("allocating rrd.live_head");
- free(rrd.stat_head);
- free(rrd.live_head);
+ rrd_free2(&rrd);
return (-1);
}
return (-1);
}
@@
-162,12
+209,11
@@
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 (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");
old_size + sizeof(ds_def_t))) ==
NULL) {
rrd_set_error("allocating rrd.ds_def");
- free(rrd.stat_head);
- free(rrd.live_head);
+ rrd_free2(&rrd);
return (-1);
}
memset(&rrd.ds_def[rrd.stat_head->ds_cnt], 0, sizeof(ds_def_t));
return (-1);
}
memset(&rrd.ds_def[rrd.stat_head->ds_cnt], 0, sizeof(ds_def_t));
@@
-180,11
+226,11
@@
int rrd_create_r(
dummychar2, &offset)) {
case 0:
case 1:
dummychar2, &offset)) {
case 0:
case 1:
- rrd_set_error("Invalid DS name
"
);
+ rrd_set_error("Invalid DS name
in [%s]",&argv[i][3]
);
break;
case 2:
case 3:
break;
case 2:
case 3:
- rrd_set_error("Invalid DS type
"
);
+ rrd_set_error("Invalid DS type
in [%s]",&argv[i][3]
);
break;
case 4: /* (%n may or may not be counted) */
case 5: /* check for duplicate datasource names */
break;
case 4: /* (%n may or may not be counted) */
case 5: /* check for duplicate datasource names */
@@
-199,8
+245,7
@@
int rrd_create_r(
rrd_set_error("invalid DS format");
}
if (rrd_test_error()) {
rrd_set_error("invalid DS format");
}
if (rrd_test_error()) {
- free(rrd.stat_head);
- free(rrd.live_head);
+ rrd_free2(&rrd);
return -1;
}
return -1;
}
@@
-223,23
+268,22
@@
int rrd_create_r(
}
if (rrd_test_error()) {
}
if (rrd_test_error()) {
- free(rrd.stat_head);
- free(rrd.live_head);
+ rrd_free2(&rrd);
return -1;
}
rrd.stat_head->ds_cnt++;
} else if (strncmp(argv[i], "RRA:", 4) == 0) {
char *argvcopy;
return -1;
}
rrd.stat_head->ds_cnt++;
} else if (strncmp(argv[i], "RRA:", 4) == 0) {
char *argvcopy;
- char *tokptr;
+ char *tokptr = "";
+ int cf_id = -1;
size_t old_size = sizeof(rra_def_t) * (rrd.stat_head->rra_cnt);
int row_cnt;
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,
+ int token_min = 4;
+ 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");
old_size + sizeof(rra_def_t))) ==
NULL) {
rrd_set_error("allocating rrd.rra_def");
- free(rrd.stat_head);
- free(rrd.live_head);
+ rrd_free2(&rrd);
return (-1);
}
memset(&rrd.rra_def[rrd.stat_head->rra_cnt], 0,
return (-1);
}
memset(&rrd.rra_def[rrd.stat_head->rra_cnt], 0,
@@
-248,6
+292,7
@@
int rrd_create_r(
argvcopy = strdup(argv[i]);
token = strtok_r(&argvcopy[4], ":", &tokptr);
token_idx = error_flag = 0;
argvcopy = strdup(argv[i]);
token = strtok_r(&argvcopy[4], ":", &tokptr);
token_idx = error_flag = 0;
+
while (token != NULL) {
switch (token_idx) {
case 0:
while (token != NULL) {
switch (token_idx) {
case 0:
@@
-255,11
+300,12
@@
int rrd_create_r(
rrd.rra_def[rrd.stat_head->rra_cnt].cf_nam) !=
1)
rrd_set_error("Failed to parse CF name");
rrd.rra_def[rrd.stat_head->rra_cnt].cf_nam) !=
1)
rrd_set_error("Failed to parse CF name");
- switch (cf_conv
-
(rrd.rra_def[rrd.stat_head->rra_cnt].cf_nam)
) {
+ cf_id = cf_conv(rrd.rra_def[rrd.stat_head->rra_cnt].cf_nam);
+
switch (cf_id
) {
case CF_MHWPREDICT:
strcpy(rrd.stat_head->version, RRD_VERSION); /* MHWPREDICT causes Version 4 */
case CF_HWPREDICT:
case CF_MHWPREDICT:
strcpy(rrd.stat_head->version, RRD_VERSION); /* MHWPREDICT causes Version 4 */
case CF_HWPREDICT:
+ token_min = 5;
/* initialize some parameters */
rrd.rra_def[rrd.stat_head->rra_cnt].par[RRA_hw_alpha].
u_val = 0.1;
/* initialize some parameters */
rrd.rra_def[rrd.stat_head->rra_cnt].par[RRA_hw_alpha].
u_val = 0.1;
@@
-270,7
+316,11
@@
int rrd_create_r(
rrd.stat_head->rra_cnt;
break;
case CF_DEVSEASONAL:
rrd.stat_head->rra_cnt;
break;
case CF_DEVSEASONAL:
+ token_min = 3;
case CF_SEASONAL:
case CF_SEASONAL:
+ if (cf_id == CF_SEASONAL){
+ token_min = 4;
+ }
/* initialize some parameters */
rrd.rra_def[rrd.stat_head->rra_cnt].
par[RRA_seasonal_gamma].u_val = 0.1;
/* initialize some parameters */
rrd.rra_def[rrd.stat_head->rra_cnt].
par[RRA_seasonal_gamma].u_val = 0.1;
@@
-278,10
+328,14
@@
int rrd_create_r(
par[RRA_seasonal_smoothing_window].u_val = 0.05;
/* fall through */
case CF_DEVPREDICT:
par[RRA_seasonal_smoothing_window].u_val = 0.05;
/* fall through */
case CF_DEVPREDICT:
+ if (cf_id == CF_DEVPREDICT){
+ token_min = 3;
+ }
rrd.rra_def[rrd.stat_head->rra_cnt].
par[RRA_dependent_rra_idx].u_cnt = -1;
break;
case CF_FAILURES:
rrd.rra_def[rrd.stat_head->rra_cnt].
par[RRA_dependent_rra_idx].u_cnt = -1;
break;
case CF_FAILURES:
+ token_min = 5;
rrd.rra_def[rrd.stat_head->rra_cnt].
par[RRA_delta_pos].u_val = 2.0;
rrd.rra_def[rrd.stat_head->rra_cnt].
rrd.rra_def[rrd.stat_head->rra_cnt].
par[RRA_delta_pos].u_val = 2.0;
rrd.rra_def[rrd.stat_head->rra_cnt].
@@
-496,14
+550,18
@@
int rrd_create_r(
if (rrd_test_error()) {
/* all errors are unrecoverable */
free(argvcopy);
if (rrd_test_error()) {
/* all errors are unrecoverable */
free(argvcopy);
- free(rrd.stat_head);
- free(rrd.live_head);
+ rrd_free2(&rrd);
return (-1);
}
token = strtok_r(NULL, ":", &tokptr);
token_idx++;
} /* end while */
free(argvcopy);
return (-1);
}
token = strtok_r(NULL, ":", &tokptr);
token_idx++;
} /* end while */
free(argvcopy);
+ if (token_idx < token_min){
+ rrd_set_error("Expected at least %i arguments for RRA but got %i",token_min,token_idx);
+ rrd_free2(&rrd);
+ return(-1);
+ }
#ifdef DEBUG
fprintf(stderr,
"Creating RRA CF: %s, dep idx %lu, current idx %lu\n",
#ifdef DEBUG
fprintf(stderr,
"Creating RRA CF: %s, dep idx %lu, current idx %lu\n",
@@
-524,16
+582,14
@@
int rrd_create_r(
if (create_hw_contingent_rras(&rrd, period, hashed_name) ==
-1) {
rrd_set_error("creating contingent RRA");
if (create_hw_contingent_rras(&rrd, period, hashed_name) ==
-1) {
rrd_set_error("creating contingent RRA");
- free(rrd.stat_head);
- free(rrd.live_head);
+ rrd_free2(&rrd);
return -1;
}
}
rrd.stat_head->rra_cnt++;
} else {
rrd_set_error("can't parse argument '%s'", argv[i]);
return -1;
}
}
rrd.stat_head->rra_cnt++;
} else {
rrd_set_error("can't parse argument '%s'", argv[i]);
- free(rrd.stat_head);
- free(rrd.live_head);
+ rrd_free2(&rrd);
return -1;
}
}
return -1;
}
}
@@
-541,18
+597,16
@@
int rrd_create_r(
if (rrd.stat_head->rra_cnt < 1) {
rrd_set_error("you must define at least one Round Robin Archive");
if (rrd.stat_head->rra_cnt < 1) {
rrd_set_error("you must define at least one Round Robin Archive");
- free(rrd.stat_head);
- free(rrd.live_head);
+ rrd_free2(&rrd);
return (-1);
}
if (rrd.stat_head->ds_cnt < 1) {
rrd_set_error("you must define at least one Data Source");
return (-1);
}
if (rrd.stat_head->ds_cnt < 1) {
rrd_set_error("you must define at least one Data Source");
- free(rrd.stat_head);
- free(rrd.live_head);
+ rrd_free2(&rrd);
return (-1);
}
return (-1);
}
- return rrd_create_fn(filename, &rrd);
+ return rrd_create_fn(filename, &rrd
, no_overwrite
);
}
void parseGENERIC_DS(
}
void parseGENERIC_DS(
@@
-570,7
+624,8
@@
void parseGENERIC_DS(
&(rrd -> ds_def[ds_idx].par[DS_mrhb_cnt].u_cnt),
minstr,maxstr);
*/
&(rrd -> ds_def[ds_idx].par[DS_mrhb_cnt].u_cnt),
minstr,maxstr);
*/
- old_locale = setlocale(LC_NUMERIC, "C");
+ old_locale = setlocale(LC_NUMERIC, NULL);
+ setlocale(LC_NUMERIC, "C");
if (sscanf(def, "%lu:%18[^:]:%18[^:]",
&(rrd->ds_def[ds_idx].par[DS_mrhb_cnt].u_cnt),
minstr, maxstr) == 3) {
if (sscanf(def, "%lu:%18[^:]:%18[^:]",
&(rrd->ds_def[ds_idx].par[DS_mrhb_cnt].u_cnt),
minstr, maxstr) == 3) {
@@
-615,9
+670,10
@@
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);
(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) {
old_size + 4 * sizeof(rra_def_t))) ==
NULL) {
+ rrd_free2(rrd);
rrd_set_error("allocating rrd.rra_def");
return (-1);
}
rrd_set_error("allocating rrd.rra_def");
return (-1);
}
@@
-674,40
+730,43
@@
int create_hw_contingent_rras(
int rrd_create_fn(
const char *file_name,
int rrd_create_fn(
const char *file_name,
- rrd_t *rrd)
+ rrd_t *rrd,
+ int no_overwrite )
{
unsigned long i, ii;
{
unsigned long i, ii;
- int rrd_file;
rrd_value_t *unknown;
int unkn_cnt;
rrd_file_t *rrd_file_dn;
rrd_t rrd_dn;
rrd_value_t *unknown;
int unkn_cnt;
rrd_file_t *rrd_file_dn;
rrd_t rrd_dn;
- unsigned flags = O_WRONLY | O_CREAT | O_TRUNC;
-#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
- flags |= O_BINARY;
-#endif
+ unsigned rrd_flags = RRD_READWRITE | RRD_CREAT;
+
+ if (no_overwrite) {
+ rrd_flags |= RRD_EXCL ;
+ }
+
+ 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
= open(file_name, flags, 0666)) < 0
) {
+ if ((rrd_file
_dn = rrd_open(file_name, rrd, rrd_flags)) == NULL
) {
rrd_set_error("creating '%s': %s", file_name, rrd_strerror(errno));
rrd_set_error("creating '%s': %s", file_name, rrd_strerror(errno));
- free(rrd->stat_head);
- free(rrd->live_head);
+ rrd_free2(rrd);
return (-1);
}
return (-1);
}
-
write(rrd_file
, rrd->stat_head, sizeof(stat_head_t));
+
rrd_write(rrd_file_dn
, rrd->stat_head, sizeof(stat_head_t));
-
write(rrd_file
, rrd->ds_def, sizeof(ds_def_t) * rrd->stat_head->ds_cnt);
+
rrd_write(rrd_file_dn
, rrd->ds_def, sizeof(ds_def_t) * rrd->stat_head->ds_cnt);
-
write(rrd_file
, rrd->rra_def,
+
rrd_write(rrd_file_dn
, rrd->rra_def,
sizeof(rra_def_t) * rrd->stat_head->rra_cnt);
sizeof(rra_def_t) * rrd->stat_head->rra_cnt);
-
write(rrd_file
, rrd->live_head, sizeof(live_head_t));
+
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_set_error("allocating pdp_prep");
- free(rrd->stat_head);
- free(rrd->live_head);
- close(rrd_file);
+ rrd_free2(rrd);
+ rrd_close(rrd_file_dn);
return (-1);
}
return (-1);
}
@@
-718,13
+777,12
@@
int rrd_create_fn(
rrd->live_head->last_up % rrd->stat_head->pdp_step;
for (i = 0; i < rrd->stat_head->ds_cnt; i++)
rrd->live_head->last_up % rrd->stat_head->pdp_step;
for (i = 0; i < rrd->stat_head->ds_cnt; i++)
-
write(rrd_file
, rrd->pdp_prep, sizeof(pdp_prep_t));
+
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_set_error("allocating cdp_prep");
- free(rrd->stat_head);
- free(rrd->live_head);
- close(rrd_file);
+ rrd_free2(rrd);
+ rrd_close(rrd_file_dn);
return (-1);
}
return (-1);
}
@@
-761,18
+819,17
@@
int rrd_create_fn(
}
for (ii = 0; ii < rrd->stat_head->ds_cnt; ii++) {
}
for (ii = 0; ii < rrd->stat_head->ds_cnt; ii++) {
-
write(rrd_file
, rrd->cdp_prep, sizeof(cdp_prep_t));
+
rrd_write(rrd_file_dn
, rrd->cdp_prep, sizeof(cdp_prep_t));
}
}
/* now, we must make sure that the rest of the rrd
struct is properly initialized */
}
}
/* 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_set_error("allocating rra_ptr");
- free(rrd->stat_head);
- free(rrd->live_head);
- close(rrd_file);
+ rrd_free2(rrd);
+ rrd_close(rrd_file_dn);
return (-1);
}
return (-1);
}
@@
-781,55
+838,57
@@
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++) {
* 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 = rr
a_random_row(
&rrd->rra_def[i]);
-
write(rrd_file
, rrd->rra_ptr, sizeof(rra_ptr_t));
+ rrd->rra_ptr->cur_row = rr
d_select_initial_row(rrd_file_dn, i,
&rrd->rra_def[i]);
+
rrd_write(rrd_file_dn
, 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");
}
/* 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);
- close(rrd_file);
+ rrd_free2(rrd);
+ rrd_close(rrd_file_dn);
return (-1);
}
for (i = 0; i < 512; ++i)
unknown[i] = DNAN;
return (-1);
}
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) {
while (unkn_cnt > 0) {
- write(rrd_file, unknown, sizeof(rrd_value_t) * min(unkn_cnt, 512));
+ if(rrd_write(rrd_file_dn, unknown, sizeof(rrd_value_t) * min(unkn_cnt, 512)) < 0)
+ {
+ rrd_set_error("creating rrd: %s", rrd_strerror(errno));
+ return -1;
+ }
unkn_cnt -= 512;
}
free(unknown);
unkn_cnt -= 512;
}
free(unknown);
- fdatasync(rrd_file);
- free(rrd->stat_head);
- free(rrd->live_head);
- if (close(rrd_file) == -1) {
+ rrd_free2(rrd);
+ if (rrd_close(rrd_file_dn) == -1) {
rrd_set_error("creating rrd: %s", rrd_strerror(errno));
return -1;
}
/* flush all we don't need out of the cache */
rrd_set_error("creating rrd: %s", rrd_strerror(errno));
return -1;
}
/* flush all we don't need out of the cache */
- rrd_file_dn = rrd_open(file_name, &rrd_dn, RRD_READONLY);
- rrd_dontneed(rrd_file_dn, &rrd_dn);
- rrd_free(&rrd_dn);
- rrd_close(rrd_file_dn);
+ rrd_init(&rrd_dn);
+ if((rrd_file_dn = rrd_open(file_name, &rrd_dn, RRD_READONLY)) != NULL)
+ {
+ rrd_dontneed(rrd_file_dn, &rrd_dn);
+ /* rrd_free(&rrd_dn); */
+ rrd_close(rrd_file_dn);
+ }
return (0);
}
return (0);
}
-static int rand_init = 0;
-
long int rra_random_row
(
- rr
a_def_t *rra
)
+
static void rrd_free2
(
+ rr
d_t *rrd
)
{
{
- if (!rand_init) {
- srandom((unsigned int) time(NULL) + (unsigned int) getpid());
- rand_init++;
- }
-
- return random() % rra->row_cnt;
+ free(rrd->live_head);
+ free(rrd->stat_head);
+ free(rrd->ds_def);
+ free(rrd->rra_def);
+ free(rrd->rra_ptr);
+ free(rrd->pdp_prep);
+ free(rrd->cdp_prep);
+ free(rrd->rrd_value);
}
}
+