Allow NULL parameters for start/stop functions

The functions that start and stop monitors and services now accept NULL
parameters.
This commit is contained in:
Markus Mäkelä 2017-05-02 11:08:56 +03:00
parent 60526f15b8
commit fce0edce8e
2 changed files with 53 additions and 44 deletions

View File

@ -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);
}
}
/**

View File

@ -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;
}