index 9ee68961b4ad6e3755fb1bf56f7d9ab85554bc1d..c48900f30f37d50fd5a5d67318464827b8a639da 100644 (file)
--- a/program/src/rrd_create.c
+++ b/program/src/rrd_create.c
rrd.stat_head->ds_cnt++;
} else if (strncmp(argv[i], "RRA:", 4) == 0) {
char *argvcopy;
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;
size_t old_size = sizeof(rra_def_t) * (rrd.stat_head->rra_cnt);
int row_cnt;
rrd_t *rrd)
{
unsigned long i, ii;
rrd_t *rrd)
{
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;
+ unsigned rrd_flags = RRD_READWRITE | RRD_CREAT;
-#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
- flags |= O_BINARY;
-#endif
+ 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_free2(rrd);
return (-1);
}
rrd_set_error("creating '%s': %s", file_name, rrd_strerror(errno));
rrd_free2(rrd);
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) {
rrd_set_error("allocating pdp_prep");
rrd_free2(rrd);
if ((rrd->pdp_prep = calloc(1, sizeof(pdp_prep_t))) == NULL) {
rrd_set_error("allocating pdp_prep");
rrd_free2(rrd);
- close(rrd_file);
+ rrd_close(rrd_file_dn);
return (-1);
}
return (-1);
}
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) {
rrd_set_error("allocating cdp_prep");
rrd_free2(rrd);
if ((rrd->cdp_prep = calloc(1, sizeof(cdp_prep_t))) == NULL) {
rrd_set_error("allocating cdp_prep");
rrd_free2(rrd);
- close(rrd_file);
+ rrd_close(rrd_file_dn);
return (-1);
}
return (-1);
}
}
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));
}
}
}
}
if ((rrd->rra_ptr = calloc(1, sizeof(rra_ptr_t))) == NULL) {
rrd_set_error("allocating rra_ptr");
rrd_free2(rrd);
if ((rrd->rra_ptr = calloc(1, sizeof(rra_ptr_t))) == NULL) {
rrd_set_error("allocating rra_ptr");
rrd_free2(rrd);
- close(rrd_file);
+ rrd_close(rrd_file_dn);
return (-1);
}
return (-1);
}
* the pointer a priori. */
for (i = 0; i < rrd->stat_head->rra_cnt; i++) {
rrd->rra_ptr->cur_row = rra_random_row(&rrd->rra_def[i]);
* the pointer a priori. */
for (i = 0; i < rrd->stat_head->rra_cnt; i++) {
rrd->rra_ptr->cur_row = rra_random_row(&rrd->rra_def[i]);
- write(rrd_file, rrd->rra_ptr, sizeof(rra_ptr_t));
+ 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");
rrd_free2(rrd);
}
/* write the empty data area */
if ((unknown = (rrd_value_t *) malloc(512 * sizeof(rrd_value_t))) == NULL) {
rrd_set_error("allocating unknown");
rrd_free2(rrd);
- close(rrd_file);
+ 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);
rrd_free2(rrd);
rrd_free2(rrd);
- if (close(rrd_file) == -1) {
+ 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);
}