summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 126cc87)
raw | patch | inline | side by side (parent: 126cc87)
author | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Tue, 14 Apr 2009 06:10:21 +0000 (06:10 +0000) | ||
committer | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Tue, 14 Apr 2009 06:10:21 +0000 (06:10 +0000) |
exactly ONCE per process.
rrd_utils.c is introduced for functions that do not have a better home. --kevin
git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk@1789 a5681a0c-68f1-0310-ab6d-d61299d08faa
rrd_utils.c is introduced for functions that do not have a better home. --kevin
git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk@1789 a5681a0c-68f1-0310-ab6d-d61299d08faa
program/src/Makefile.am | patch | blob | history | |
program/src/librrd.sym.in.in | patch | blob | history | |
program/src/rrd.h | patch | blob | history | |
program/src/rrd_daemon.c | patch | blob | history | |
program/src/rrd_open.c | patch | blob | history | |
program/src/rrd_restore.c | patch | blob | history | |
program/src/rrd_utils.c | [new file with mode: 0644] | patch | blob |
index 35ed960ee23386b31baf4baf2ddd812f0c57e885..129e3adfb8862adb8d3b3e75055fe94506c814e4 100644 (file)
--- a/program/src/Makefile.am
+++ b/program/src/Makefile.am
rrd_client.c \
rrd_nan_inf.c \
rrd_rpncalc.c \
+ rrd_utils.c \
rrd_update.c
RRD_C_FILES = \
index b4e848495d1babd290275a91e774922ce1df7954..0a7a699dca9da1713ecbf574597957b5b8122c9e 100644 (file)
rrd_open
rrd_parsetime
rrd_proc_start_end
+rrd_random
rrd_read
rrd_resize
rrd_restore
diff --git a/program/src/rrd.h b/program/src/rrd.h
index 67c213f562074190fd71d60f757a54bbec86c3e5..fd506d94e9c4533782d75e0212eb3e6775456a3d 100644 (file)
--- a/program/src/rrd.h
+++ b/program/src/rrd.h
/* 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
index dcca55d755f53d52513d3e1ba1f9c3a08e5d76bd..7a7ae88696a9add76a304c792d9d6d88a601d87d 100644 (file)
--- a/program/src/rrd_daemon.c
+++ b/program/src/rrd_daemon.c
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
diff --git a/program/src/rrd_open.c b/program/src/rrd_open.c
index 16545145ba214444219fbd09b72e3765ae2d7a8e..f74c6d8a677ea8c0e3068f271b8d970f61441f81 100644 (file)
--- a/program/src/rrd_open.c
+++ b/program/src/rrd_open.c
#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;
}
-
index e9363c6ecea7e392b73e2d545373f537fc591b37..9af8ab00604e0941df9ac9d054ea1095279e7889 100644 (file)
#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 */
diff --git a/program/src/rrd_utils.c b/program/src/rrd_utils.c
--- /dev/null
+++ b/program/src/rrd_utils.c
@@ -0,0 +1,36 @@
+/**
+ * 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();
+}