rrd_client.c \
rrd_nan_inf.c \
rrd_rpncalc.c \
+ rrd_utils.c \
rrd_update.c
RRD_C_FILES = \
rrd_open
rrd_parsetime
rrd_proc_start_end
+rrd_random
rrd_read
rrd_resize
rrd_restore
/* int rrd_test_error_r (rrd_context_t *); */
/* char *rrd_get_error_r (rrd_context_t *); */
+/** UTILITY FUNCTIONS */
+
+ long rrd_random(void);
+
/*
* The following functions are _internal_ functions needed to read the raw RRD
* files. Since they are _internal_ they may change with the file format and
ci->last_flush_time = when;
if (config_write_jitter > 0)
- ci->last_flush_time += (random() % config_write_jitter);
+ ci->last_flush_time += (rrd_random() % config_write_jitter);
}
/* remove_from_queue
#define MEMBLK 8192
#ifdef WIN32
-# define random() rand()
-# define srandom(x) srand(x)
-# define getpid() 0
-
#define _LK_UNLCK 0 /* Unlock */
#define _LK_LOCK 1 /* Lock */
#define _LK_NBLCK 2 /* Non-blocking lock */
#endif
#endif
-long int rra_random_row(
- rra_def_t *);
-
-
/* Open a database file, return its header and an open filehandle,
* positioned to the first cdp in the first rra.
* In the error path of rrd_open, only rrd_free(&rrd) has to be called
rra_def_t *rra
)
{
- return rra_random_row(rra);
-}
-
-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;
+ return rrd_random() % rra->row_cnt;
}
-
#ifndef WIN32
# include <unistd.h> /* for off_t */
#else
-# define random() rand()
-# define srandom(x) srand(x)
-# define getpid() 0
typedef size_t ssize_t;
typedef long off_t;
#endif
}
/* Set the RRA pointer to a random location */
- cur_rra_ptr->cur_row = random() % cur_rra_def->row_cnt;
+ cur_rra_ptr->cur_row = rrd_random() % cur_rra_def->row_cnt;
return (status);
} /* int parse_tag_rra */
{
rrd_t *rrd;
- srandom((unsigned int) time(NULL) + (unsigned int) getpid());
/* init rrd clean */
optind = 0;
opterr = 0; /* initialize getopt */
--- /dev/null
+/**
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; only version 2 of the License is applicable.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ **/
+
+#include "rrd_tool.h"
+
+#include <stdlib.h>
+
+#ifdef WIN32
+# define random() rand()
+# define srandom(x) srand(x)
+# define getpid() 0
+#endif /* WIN32 */
+
+/* make sure that the random number generator seeded EXACTLY ONCE */
+long rrd_random(void)
+{
+ static int rand_init = 0;
+ if (!rand_init) {
+ srandom((unsigned int) time(NULL) + (unsigned int) getpid());
+ rand_init++;
+ }
+
+ return random();
+}