=head2 CURRENTLY IMPLEMENTED THREAD SAFE FUNCTIONS
Currently there exist thread-safe variants of C<rrd_update>,
-C<rrd_create>, C<rrd_dump>, C<rrd_info> and C<rrd_last>.
+C<rrd_create>, C<rrd_dump>, C<rrd_info>, C<rrd_last>, and C<rrd_fetch>.
=head1 AUTHOR
*/
#define FNV1_32_INIT ((Fnv32_t)0x811c9dc5)
-Fnv32_t fnv_32_buf(void *, size_t, Fnv32_t);
+Fnv32_t fnv_32_buf(const void *, size_t, Fnv32_t);
-Fnv32_t fnv_32_str(char *, Fnv32_t );
+Fnv32_t fnv_32_str(const char *, Fnv32_t );
-unsigned long FnvHash(char *);
+unsigned long FnvHash(const char *);
#endif /* __FNV_H__ */
* argument on the first call to either fnv_32_buf() or fnv_32_str().
*/
Fnv32_t
-fnv_32_buf(void *buf, size_t len, Fnv32_t hval)
+fnv_32_buf(const void *buf, size_t len, Fnv32_t hval)
{
- unsigned char *bp = (unsigned char *)buf; /* start of buffer */
- unsigned char *be = bp + len; /* beyond end of buffer */
+ const unsigned char *bp = (const unsigned char *)buf; /* start of buffer */
+ const unsigned char *be = bp + len; /* beyond end of buffer */
/*
* FNV-1 hash each octet in the buffer
* argument on the first call to either fnv_32_buf() or fnv_32_str().
*/
Fnv32_t
-fnv_32_str(char *str, Fnv32_t hval)
+fnv_32_str(const char *str, Fnv32_t hval)
{
- unsigned char *s = (unsigned char *)str; /* unsigned string */
+ const unsigned char *s = (const unsigned char *)str; /* unsigned string */
/*
* FNV-1 hash each octet in the buffer
}
/* a wrapper function for fnv_32_str */
-unsigned long FnvHash(char *str)
+unsigned long FnvHash(const char *str)
{
return fnv_32_str(str,FNV1_32_INIT);
}
char ***, rrd_value_t **);
/* thread-safe (hopefully) */
-int rrd_create_r(char *filename,
+int rrd_create_r(const char *filename,
unsigned long pdp_step, time_t last_up,
- int argc, char **argv);
+ int argc, const char **argv);
/* NOTE: rrd_update_r are only thread-safe if no at-style time
specifications get used!!! */
-int rrd_update_r(char *filename, char *_template,
- int argc, char **argv);
+int rrd_update_r(const char *filename, const char *_template,
+ int argc, const char **argv);
+int rrd_fetch_r(const char *filename, const char* cf,
+ time_t *start, time_t *end,
+ unsigned long *step,
+ unsigned long *ds_cnt,
+ char ***ds_namv,
+ rrd_value_t **data);
int rrd_dump_r(const char *filename, char *outname);
time_t rrd_last_r(const char *filename);
time_t rrd_first_r(const char *filename, int rraindex);
#include "rrd_is_thread_safe.h"
-unsigned long FnvHash(char *str);
+unsigned long FnvHash(const char *str);
int create_hw_contingent_rras(rrd_t *rrd, unsigned short period, unsigned long hashed_name);
-void parseGENERIC_DS(char *def,rrd_t *rrd, int ds_idx);
+void parseGENERIC_DS(const char *def,rrd_t *rrd, int ds_idx);
int
rrd_create(int argc, char **argv)
/* #define DEBUG */
int
-rrd_create_r(char *filename,
+rrd_create_r(const char *filename,
unsigned long pdp_step, time_t last_up,
- int argc, char **argv)
+ int argc, const char **argv)
{
rrd_t rrd;
long i;
return rrd_create_fn(filename, &rrd);
}
-void parseGENERIC_DS(char *def,rrd_t *rrd, int ds_idx)
+void parseGENERIC_DS(const char *def,rrd_t *rrd, int ds_idx)
{
char minstr[DS_NAM_SIZE], maxstr[DS_NAM_SIZE];
/*
/* create and empty rrd file according to the specs given */
int
-rrd_create_fn(char *file_name, rrd_t *rrd)
+rrd_create_fn(const char *file_name, rrd_t *rrd)
{
unsigned long i,ii;
FILE *rrd_file;
*****************************************************************************/
#include "rrd_tool.h"
+
+#include "rrd_is_thread_safe.h"
/*#define DEBUG*/
int
long step_tmp =1;
time_t start_tmp=0, end_tmp=0;
- enum cf_en cf_idx;
+ const char *cf;
struct rrd_time_value start_tv, end_tv;
char *parsetime_error = NULL;
rrd_set_error("not enough arguments");
return -1;
}
-
- if ((int)(cf_idx=cf_conv(argv[optind+1])) == -1 ){
- return -1;
- }
- if (rrd_fetch_fn(argv[optind],cf_idx,start,end,step,ds_cnt,ds_namv,data) == -1)
+ cf = argv[optind+1];
+
+ if (rrd_fetch_r(argv[optind],cf,start,end,step,ds_cnt,ds_namv,data) == -1)
return(-1);
return (0);
}
int
+rrd_fetch_r(
+ const char *filename, /* name of the rrd */
+ const char *cf, /* which consolidation function ?*/
+ time_t *start,
+ time_t *end, /* which time frame do you want ?
+ * will be changed to represent reality */
+ unsigned long *step, /* which stepsize do you want?
+ * will be changed to represent reality */
+ unsigned long *ds_cnt, /* number of data sources in file */
+ char ***ds_namv, /* names of data_sources */
+ rrd_value_t **data) /* two dimensional array containing the data */
+{
+ enum cf_en cf_idx;
+
+ if ((int)(cf_idx=cf_conv(cf)) == -1 ){
+ return -1;
+ }
+
+ return (rrd_fetch_fn(filename,cf_idx,start,end,step,ds_cnt,ds_namv,data));
+}
+
+int
rrd_fetch_fn(
- char *filename, /* name of the rrd */
+ const char *filename, /* name of the rrd */
enum cf_en cf_idx, /* which consolidation function ?*/
time_t *start,
time_t *end, /* which time frame do you want ?
}
-enum cf_en cf_conv(char *string)
+enum cf_en cf_conv(const char *string)
{
converter(AVERAGE,CF_AVERAGE)
return 0;
}
-void parseCDEF_DS(char *def,rrd_t *rrd, int ds_idx)
+void parseCDEF_DS(const char *def,rrd_t *rrd, int ds_idx)
{
rpnp_t *rpnp = NULL;
rpn_cdefds_t *rpnc = NULL;
void rpnstack_init(rpnstack_t *rpnstack);
void rpnstack_free(rpnstack_t *rpnstack);
-void parseCDEF_DS(char *def, rrd_t *rrd, int ds_idx);
+void parseCDEF_DS(const char *def, rrd_t *rrd, int ds_idx);
long lookup_DS(void *rrd_vptr, char *ds_name);
short rpn_compact(rpnp_t *rpnp,rpn_cdefds_t **rpnc,short *count);
int PngSize(FILE *, long *, long *);
-int rrd_create_fn(char *file_name, rrd_t *rrd);
-int rrd_fetch_fn(char *filename, enum cf_en cf_idx,
+int rrd_create_fn(const char *file_name, rrd_t *rrd);
+int rrd_fetch_fn(const char *filename, enum cf_en cf_idx,
time_t *start,time_t *end,
unsigned long *step,
unsigned long *ds_cnt,
#define RRD_READONLY 0
#define RRD_READWRITE 1
-enum cf_en cf_conv(char *string);
+enum cf_en cf_conv(const char *string);
enum dst_en dst_conv(char *string);
long ds_match(rrd_t *rrd,char *ds_nam);
double rrd_diff(char *a, char *b);
unsigned short CDP_scratch_idx, FILE *rrd_file,
info_t *pcdp_summary, time_t *rra_time);
#endif
-int rrd_update_r(char *filename, char *tmplt, int argc, char **argv);
-int _rrd_update(char *filename, char *tmplt, int argc, char **argv,
+int rrd_update_r(const char *filename, const char *tmplt, int argc, const char **argv);
+int _rrd_update(const char *filename, const char *tmplt, int argc, const char **argv,
info_t*);
#define IFDNAN(X,Y) (isnan(X) ? (Y) : (X));
}
int
-rrd_update_r(char *filename, char *tmplt, int argc, char **argv)
+rrd_update_r(const char *filename, const char *tmplt, int argc, const char **argv)
{
return _rrd_update(filename, tmplt, argc, argv, NULL);
}
int
-_rrd_update(char *filename, char *tmplt, int argc, char **argv,
+_rrd_update(const char *filename, const char *tmplt, int argc, const char **argv,
info_t *pcdp_summary)
{
/* we should work on a writeable copy here */
char *dsname;
unsigned int tmpl_len;
- tmplt = strdup(tmplt);
- dsname = tmplt;
+ char *tmplt_copy = strdup(tmplt);
+ dsname = tmplt_copy;
tmpl_cnt = 1; /* the first entry is the time */
- tmpl_len = strlen(tmplt);
+ tmpl_len = strlen(tmplt_copy);
for(i=0;i<=tmpl_len ;i++) {
- if (tmplt[i] == ':' || tmplt[i] == '\0') {
- tmplt[i] = '\0';
+ if (tmplt_copy[i] == ':' || tmplt_copy[i] == '\0') {
+ tmplt_copy[i] = '\0';
if (tmpl_cnt>rrd.stat_head->ds_cnt){
rrd_set_error("tmplt contains more DS definitions than RRD");
free(updvals); free(pdp_temp);
if ((tmpl_idx[tmpl_cnt++] = ds_match(&rrd,dsname)) == -1){
rrd_set_error("unknown DS name '%s'",dsname);
free(updvals); free(pdp_temp);
- free(tmplt);
+ free(tmplt_copy);
free(tmpl_idx); rrd_free(&rrd);
fclose(rrd_file); return(-1);
} else {
/* the first element is always the time */
tmpl_idx[tmpl_cnt-1]++;
- /* go to the next entry on the tmplt */
- dsname = &tmplt[i+1];
+ /* go to the next entry on the tmplt_copy */
+ dsname = &tmplt_copy[i+1];
/* fix the damage we did before */
if (i<tmpl_len) {
- tmplt[i]=':';
+ tmplt_copy[i]=':';
}
}
}
}
- free(tmplt);
+ free(tmplt_copy);
}
if ((pdp_new = malloc(sizeof(rrd_value_t)
*rrd.stat_head->ds_cnt))==NULL){