From b06fd12526849dd65836a1899a4cabca4525a96d Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 19 Jun 2015 19:26:19 -0400 Subject: [PATCH] Quagga: Fix code to use srandom/random Quagga was using a mix of srand/rand and srandom/random. Consolidate to use srandom/random which are the POSIX versions of random number generators Signed-off-by: Donald Sharp --- bgpd/bgp_main.c | 2 +- bgpd/bgp_routemap.c | 13 +------------ isisd/isis_main.c | 2 +- isisd/isis_misc.c | 2 +- lib/command.c | 2 +- ospf6d/ospf6_main.c | 2 +- ripd/ripd.c | 4 ++-- ripngd/ripngd.c | 4 ++-- 8 files changed, 10 insertions(+), 21 deletions(-) diff --git a/bgpd/bgp_main.c b/bgpd/bgp_main.c index 7fa80cc9c9..f873aba493 100644 --- a/bgpd/bgp_main.c +++ b/bgpd/bgp_main.c @@ -490,7 +490,7 @@ main (int argc, char **argv) /* Initializations. */ - srand (time (NULL)); + srandom (time (NULL)); signal_init (bm->master, array_size(bgp_signals), bgp_signals); zprivs_init (&bgpd_privs); cmd_init (1); diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c index ab22a455d2..a7d62a6b37 100644 --- a/bgpd/bgp_routemap.c +++ b/bgpd/bgp_routemap.c @@ -892,12 +892,7 @@ static route_map_result_t route_match_probability (void *rule, struct prefix *prefix, route_map_object_t type, void *object) { - unsigned long r; -#if _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE >= 500 - r = random(); -#else - r = (unsigned long) rand(); -#endif + long r = random(); switch (*(long *) rule) { @@ -919,12 +914,6 @@ route_match_probability_compile (const char *arg) long *lobule; unsigned perc; -#if _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE >= 500 - srandom (time (NULL)); -#else - srand (time (NULL)); -#endif - perc = atoi (arg); lobule = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (long)); diff --git a/isisd/isis_main.c b/isisd/isis_main.c index f2fe4ef71f..343c683f48 100644 --- a/isisd/isis_main.c +++ b/isisd/isis_main.c @@ -327,7 +327,7 @@ main (int argc, char **argv, char **envp) master = thread_master_create (); /* random seed from time */ - srand (time (NULL)); + srandom (time (NULL)); /* * initializations diff --git a/isisd/isis_misc.c b/isisd/isis_misc.c index 230fe24387..f19b44155a 100644 --- a/isisd/isis_misc.c +++ b/isisd/isis_misc.c @@ -510,7 +510,7 @@ isis_jitter (unsigned long timer, unsigned long jitter) * most IS-IS timers are no longer than 16 bit */ - j = 1 + (int) ((RANDOM_SPREAD * rand ()) / (RAND_MAX + 1.0)); + j = 1 + (int) ((RANDOM_SPREAD * random ()) / (RAND_MAX + 1.0)); k = timer - (timer * (100 - jitter)) / 100; diff --git a/lib/command.c b/lib/command.c index 85506adefe..d080d6cc0b 100644 --- a/lib/command.c +++ b/lib/command.c @@ -4209,7 +4209,7 @@ cmd_init (int terminal) vrf_install_commands (); } - srand(time(NULL)); + srandom(time(NULL)); } static void diff --git a/ospf6d/ospf6_main.c b/ospf6d/ospf6_main.c index 52dc6677f0..84c98b885f 100644 --- a/ospf6d/ospf6_main.c +++ b/ospf6d/ospf6_main.c @@ -243,7 +243,7 @@ main (int argc, char *argv[], char *envp[]) progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]); /* Seed random number for LSA ID */ - srand (time(NULL)); + srandom (time(NULL)); /* Command line argument treatment. */ while (1) diff --git a/ripd/ripd.c b/ripd/ripd.c index fc3ad3adb3..42f1015453 100644 --- a/ripd/ripd.c +++ b/ripd/ripd.c @@ -2867,7 +2867,7 @@ rip_update_jitter (unsigned long time) if (jitter_input < JITTER_BOUND) jitter_input = JITTER_BOUND; - jitter = (((rand () % ((jitter_input * 2) + 1)) - jitter_input)); + jitter = (((random () % ((jitter_input * 2) + 1)) - jitter_input)); return jitter/JITTER_BOUND; } @@ -4140,7 +4140,7 @@ void rip_init (void) { /* Randomize for triggered update random(). */ - srand (time (NULL)); + srandom (time (NULL)); /* Install top nodes. */ install_node (&rip_node, config_write_rip); diff --git a/ripngd/ripngd.c b/ripngd/ripngd.c index 4eed40b94a..13884ff3b3 100644 --- a/ripngd/ripngd.c +++ b/ripngd/ripngd.c @@ -1874,7 +1874,7 @@ ripng_request (struct interface *ifp) static int ripng_update_jitter (int time) { - return ((rand () % (time + 1)) - (time / 2)); + return ((random () % (time + 1)) - (time / 2)); } void @@ -2928,7 +2928,7 @@ void ripng_init () { /* Randomize. */ - srand (time (NULL)); + srandom (time (NULL)); /* Install RIPNG_NODE. */ install_node (&cmd_ripng_node, ripng_config_write); -- 2.39.5