From 8482c560f79f2f6226e6180f011f0be88096bd2b Mon Sep 17 00:00:00 2001 From: Mark Riddoch Date: Wed, 24 Jul 2013 14:44:29 +0200 Subject: [PATCH] Shutdown all monitors when shutting down the gateway --- core/gateway.c | 4 ++++ core/monitor.c | 18 ++++++++++++++++++ core/secrets.c | 2 +- include/monitor.h | 1 + 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/core/gateway.c b/core/gateway.c index 4704cd1dd..feda8a95e 100644 --- a/core/gateway.c +++ b/core/gateway.c @@ -50,6 +50,7 @@ #include #include +#include #include #include @@ -407,6 +408,9 @@ char ddopt[1024]; for (n = 0; n < n_threads - 1; n++) thread_wait(threads[n]); + /* Stop all the monitors */ + monitorStopAll(); + skygw_log_write(NULL, LOGFILE_MESSAGE, "MaxScale shutdown, PID %i\n", getpid()); return 0; diff --git a/core/monitor.c b/core/monitor.c index 922e17e82..2216242d3 100644 --- a/core/monitor.c +++ b/core/monitor.c @@ -104,6 +104,24 @@ MONITOR *ptr; free(mon); } +/** + * Shutdown all running monitors + */ +void +monitorStopAll() +{ +MONITOR *ptr; + + spinlock_acquire(&monLock); + ptr = allMonitors; + while (ptr) + { + ptr->module->stopMonitor(ptr->handle); + ptr = ptr->next; + } + spinlock_release(&monLock); +} + /** * Add a server to a monitor. Simply register the server that needs to be * monitored to the running monitor module. diff --git a/core/secrets.c b/core/secrets.c index e2839dea4..2110ef6c3 100644 --- a/core/secrets.c +++ b/core/secrets.c @@ -39,7 +39,7 @@ static int secrets_random_str(unsigned char *output, int len) { int i; - srand(time(0L)); + srand((unsigned long )time(0L) ^ (unsigned long )output); for ( i = 0; i < len; ++i ) { diff --git a/include/monitor.h b/include/monitor.h index 8b9a0b5c8..3b95bd1b8 100644 --- a/include/monitor.h +++ b/include/monitor.h @@ -78,4 +78,5 @@ extern MONITOR *monitor_alloc(char *, char *); extern void monitor_free(MONITOR *); extern void monitorAddServer(MONITOR *, SERVER *); extern void monitorAddUser(MONITOR *, char *, char *); +extern void monitorStopAll(); #endif