# HG changeset patch # User Carl Byington # Date 1211513992 25200 # Node ID 4a81cc2da570775e826e4d9b58b5bb66f5d54050 # Parent bb3f804f13a0c3663318192c86fe10802f12e067 fix hourly randomization for unsynch diff -r bb3f804f13a0 -r 4a81cc2da570 src/routeflapper.cpp --- a/src/routeflapper.cpp Mon May 19 21:45:45 2008 -0700 +++ b/src/routeflapper.cpp Thu May 22 20:39:52 2008 -0700 @@ -48,7 +48,8 @@ //////////////////////////////////////////////// // syslog a message // -void my_syslog(char *text) { +void my_syslog(char *text) +{ if (use_syslog) { pthread_mutex_lock(&syslog_mutex); if (!syslog_opened) { @@ -67,7 +68,8 @@ // reload the config // CONFIG* new_conf(); -CONFIG* new_conf() { +CONFIG* new_conf() +{ CONFIG *newc = new CONFIG; pthread_mutex_lock(&config_mutex); newc->generation = generation++; @@ -90,21 +92,18 @@ // thread to update hourly statistics // void* hourly_update(void *arg); -void* hourly_update(void *arg) { +void* hourly_update(void *arg) +{ + unsigned seed = (unsigned)time(NULL); while (loader_run) { - int ran = (rand() % 600) - 300; // random(-5min,+5min) + int ran = (rand_r(&seed) % 600) - 300; // random(-5min,+5min) int hour = 3600 - 60 + ran; // 59 minutes +- random up to 5 minutes. int period = (hour + 10) / 20; // twenty periods ... - int count = 0; - while (loader_run) { + for (int count = 0; loader_run && (count < 20); count++) { sleep(period); + } if (!loader_run) break; // ... so we only wait about 3 minutes to terminate - count++; - if (count == 20) { routing_hourly_update(); // roughly an hour - count = 0; - }; - } } } @@ -114,7 +113,8 @@ // and reload when needed. // void* config_loader(void *arg); -void* config_loader(void *arg) { +void* config_loader(void *arg) +{ typedef set configp_set; while (loader_run) { sleep(180); // look for modifications every 3 minutes