index 6f4c8043da656128e2adc2be9971c54edf6a8227..3bdd809c670000aedf08dfe0184170e090f8f67f 100644 (file)
--- a/program/src/rrd_create.c
+++ b/program/src/rrd_create.c
/*****************************************************************************
- * RRDtool 1.2.23 Copyright by Tobi Oetiker, 1997-2007
+ * RRDtool 1.2.30 Copyright by Tobi Oetiker, 1997-2009
*****************************************************************************
* rrd_create.c creates new rrds
*****************************************************************************/
+#include <stdlib.h>
+#include <time.h>
+
#include "rrd_tool.h"
#include "rrd_rpncalc.h"
#include "rrd_hw.h"
unsigned long FnvHash(const char *str);
int create_hw_contingent_rras(rrd_t *rrd, unsigned short period, unsigned long hashed_name);
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, char **argv)
break;
default:
rrd.rra_def[rrd.stat_head->rra_cnt].pdp_cnt = atoi(token);
+ if (atoi(token) < 1)
+ rrd_set_error("Invalid step: must be >= 1");
break;
}
break;
FILE *rrd_file;
rrd_value_t *unknown;
int unkn_cnt;
-
- long rrd_head_size;
-
+
if ((rrd_file = fopen(file_name,"wb")) == NULL ) {
rrd_set_error("creating '%s': %s",file_name, rrd_strerror(errno));
- free(rrd->stat_head);
- rrd->stat_head = NULL;
- free(rrd->ds_def);
- rrd->ds_def = NULL;
- free(rrd->rra_def);
- rrd->rra_def = NULL;
+ rrd_free(rrd);
return(-1);
}
* 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]);
fwrite( rrd->rra_ptr, sizeof(rra_ptr_t),1,rrd_file);
}
- rrd_head_size = ftell(rrd_file);
-
+
/* write the empty data area */
if ((unknown = (rrd_value_t *)malloc(512 * sizeof(rrd_value_t))) == NULL) {
rrd_set_error("allocating unknown");
return(-1);
}
-#ifdef HAVE_POSIX_FADVISE
- /* this file is not going to be read again any time
- soon, so we drop everything except the header portion from
- the buffer cache. for this to work, we have to fdsync the file
- first though. This will not be all that fast, but 'good' data
- like other rrdfiles headers will stay in cache. Now this only works if creating
- a single rrd file is not too large, but I assume this should not be the case
- in general. Otherwhise we would have to sync and release while writing all
- the unknown data. */
- fdatasync(fileno(rrd_file));
- if (0 != posix_fadvise(fileno(rrd_file), rrd_head_size, 0, POSIX_FADV_DONTNEED)) {
- rrd_set_error("setting POSIX_FADV_DONTNEED on '%s': %s",file_name, rrd_strerror(errno));
- fclose(rrd_file);
- return(-1);
- }
-#endif
-
fclose(rrd_file);
rrd_free(rrd);
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;
+}