From fce0edce8eb3f2bc3ffdb55a7a85eaf50cfd6b3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Tue, 2 May 2017 11:08:56 +0300 Subject: [PATCH] Allow NULL parameters for start/stop functions The functions that start and stop monitors and services now accept NULL parameters. --- server/core/monitor.cc | 58 +++++++++++++++++++++++------------------- server/core/service.cc | 39 +++++++++++++++------------- 2 files changed, 53 insertions(+), 44 deletions(-) diff --git a/server/core/monitor.cc b/server/core/monitor.cc index 3c58b3577..9f2299ff1 100644 --- a/server/core/monitor.cc +++ b/server/core/monitor.cc @@ -164,18 +164,21 @@ monitor_free(MXS_MONITOR *mon) void monitorStart(MXS_MONITOR *monitor, const MXS_CONFIG_PARAMETER* params) { - spinlock_acquire(&monitor->lock); - - if ((monitor->handle = (*monitor->module->startMonitor)(monitor, params))) + if (monitor) { - monitor->state = MONITOR_STATE_RUNNING; - } - else - { - MXS_ERROR("Failed to start monitor '%s'.", monitor->name); - } + spinlock_acquire(&monitor->lock); - spinlock_release(&monitor->lock); + if ((monitor->handle = (*monitor->module->startMonitor)(monitor, params))) + { + monitor->state = MONITOR_STATE_RUNNING; + } + else + { + MXS_ERROR("Failed to start monitor '%s'.", monitor->name); + } + + spinlock_release(&monitor->lock); + } } /** @@ -203,26 +206,29 @@ void monitorStartAll() void monitorStop(MXS_MONITOR *monitor) { - spinlock_acquire(&monitor->lock); - - /** Only stop the monitor if it is running */ - if (monitor->state == MONITOR_STATE_RUNNING) + if (monitor) { - monitor->state = MONITOR_STATE_STOPPING; - monitor->module->stopMonitor(monitor); - monitor->state = MONITOR_STATE_STOPPED; + spinlock_acquire(&monitor->lock); - MXS_MONITOR_SERVERS* db = monitor->databases; - while (db) + /** Only stop the monitor if it is running */ + if (monitor->state == MONITOR_STATE_RUNNING) { - // TODO: Create a generic entry point for this or move it inside stopMonitor - mysql_close(db->con); - db->con = NULL; - db = db->next; - } - } + monitor->state = MONITOR_STATE_STOPPING; + monitor->module->stopMonitor(monitor); + monitor->state = MONITOR_STATE_STOPPED; - spinlock_release(&monitor->lock); + MXS_MONITOR_SERVERS* db = monitor->databases; + while (db) + { + // TODO: Create a generic entry point for this or move it inside stopMonitor + mysql_close(db->con); + db->con = NULL; + db = db->next; + } + } + + spinlock_release(&monitor->lock); + } } /** diff --git a/server/core/service.cc b/server/core/service.cc index a523fc379..de6880f22 100644 --- a/server/core/service.cc +++ b/server/core/service.cc @@ -627,23 +627,24 @@ int service_launch_all() bool serviceStop(SERVICE *service) { - SERV_LISTENER *port; int listeners = 0; - port = service->ports; - while (port) + if (service) { - if (port->listener && port->listener->session->state == SESSION_STATE_LISTENER) + for (SERV_LISTENER * port = service->ports; port; port = port->next) { - if (poll_remove_dcb(port->listener) == 0) + if (port->listener && port->listener->session->state == SESSION_STATE_LISTENER) { - port->listener->session->state = SESSION_STATE_LISTENER_STOPPED; - listeners++; + if (poll_remove_dcb(port->listener) == 0) + { + port->listener->session->state = SESSION_STATE_LISTENER_STOPPED; + listeners++; + } } } - port = port->next; + + service->state = SERVICE_STATE_STOPPED; } - service->state = SERVICE_STATE_STOPPED; return listeners > 0; } @@ -658,23 +659,25 @@ bool serviceStop(SERVICE *service) */ bool serviceStart(SERVICE *service) { - SERV_LISTENER *port; int listeners = 0; - port = service->ports; - while (port) + if (service) { - if (port->listener && port->listener->session->state == SESSION_STATE_LISTENER_STOPPED) + for (SERV_LISTENER* port = service->ports; port; port = port->next) { - if (poll_add_dcb(port->listener) == 0) + if (port->listener && port->listener->session->state == SESSION_STATE_LISTENER_STOPPED) { - port->listener->session->state = SESSION_STATE_LISTENER; - listeners++; + if (poll_add_dcb(port->listener) == 0) + { + port->listener->session->state = SESSION_STATE_LISTENER; + listeners++; + } } } - port = port->next; + + service->state = SERVICE_STATE_STARTED; } - service->state = SERVICE_STATE_STARTED; + return listeners > 0; }