From 1e084b78b1a514d9157ecb074918c4ba4f3e57fb Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Wed, 16 May 2018 12:47:40 +0300 Subject: [PATCH] MXS-1775 MonitorInstance::m_script is now a std::string --- include/maxscale/monitor.hh | 2 +- server/core/monitor.cc | 10 +--------- server/modules/monitor/auroramon/auroramon.cc | 2 +- server/modules/monitor/galeramon/galeramon.cc | 7 +++---- server/modules/monitor/grmon/grmon.cc | 3 --- server/modules/monitor/grmon/grmon.hh | 1 - server/modules/monitor/mmmon/mmmon.cc | 2 +- server/modules/monitor/ndbclustermon/ndbclustermon.cc | 2 +- 8 files changed, 8 insertions(+), 21 deletions(-) diff --git a/include/maxscale/monitor.hh b/include/maxscale/monitor.hh index e49e5e91d..8e259cfad 100644 --- a/include/maxscale/monitor.hh +++ b/include/maxscale/monitor.hh @@ -43,7 +43,7 @@ protected: int m_status; /**< The current status of the monitor. */ MXS_MONITOR* m_monitor; /**< The generic monitor structure. */ int32_t m_shutdown; /**< Non-zero if the monitor should shut down. */ - char* m_script; /**< Launchable script. */ + std::string m_script; /**< Launchable script. */ uint64_t m_events; /**< Enabled monitor events. */ bool m_checked; /**< Whether server access has been checked. */ diff --git a/server/core/monitor.cc b/server/core/monitor.cc index 37a565f26..5333f8982 100644 --- a/server/core/monitor.cc +++ b/server/core/monitor.cc @@ -2510,7 +2510,6 @@ MonitorInstance::MonitorInstance(MXS_MONITOR* pMonitor) : m_status(0) , m_monitor(pMonitor) , m_shutdown(0) - , m_script(NULL) , m_events(0) , m_thread(0) { @@ -2519,7 +2518,6 @@ MonitorInstance::MonitorInstance(MXS_MONITOR* pMonitor) MonitorInstance::~MonitorInstance() { ss_dassert(!m_thread); - ss_dassert(!m_script); } void MonitorInstance::stop() @@ -2530,9 +2528,6 @@ void MonitorInstance::stop() thread_wait(m_thread); m_thread = 0; m_shutdown = 0; - - MXS_FREE(m_script); - m_script = NULL; } bool MonitorInstance::start(const MXS_CONFIG_PARAMETER* pParams) @@ -2541,7 +2536,6 @@ bool MonitorInstance::start(const MXS_CONFIG_PARAMETER* pParams) ss_dassert(!m_shutdown); ss_dassert(!m_thread); - ss_dassert(!m_script); if (!m_checked) { @@ -2557,7 +2551,7 @@ bool MonitorInstance::start(const MXS_CONFIG_PARAMETER* pParams) if (m_checked) { - m_script = config_copy_string(pParams, "script"); + m_script = config_get_string(pParams, "script"); m_events = config_get_enum(pParams, "events", mxs_monitor_event_enum_values); configure(pParams); @@ -2565,8 +2559,6 @@ bool MonitorInstance::start(const MXS_CONFIG_PARAMETER* pParams) if (thread_start(&m_thread, &maxscale::MonitorInstance::main, this, 0) == NULL) { MXS_ERROR("Failed to start monitor thread for monitor '%s'.", m_monitor->name); - MXS_FREE(m_script); - m_script = NULL; } else { diff --git a/server/modules/monitor/auroramon/auroramon.cc b/server/modules/monitor/auroramon/auroramon.cc index 277291b73..0f35a6906 100644 --- a/server/modules/monitor/auroramon/auroramon.cc +++ b/server/modules/monitor/auroramon/auroramon.cc @@ -149,7 +149,7 @@ void AuroraMonitor::main() * After updating the status of all servers, check if monitor events * need to be launched. */ - mon_process_state_changes(m_monitor, m_script, m_events); + mon_process_state_changes(m_monitor, m_script.empty() ? NULL : m_script.c_str(), m_events); servers_status_current_to_pending(m_monitor); store_server_journal(m_monitor, NULL); diff --git a/server/modules/monitor/galeramon/galeramon.cc b/server/modules/monitor/galeramon/galeramon.cc index a654306a5..479b334f8 100644 --- a/server/modules/monitor/galeramon/galeramon.cc +++ b/server/modules/monitor/galeramon/galeramon.cc @@ -134,7 +134,6 @@ GaleraMonitor::GaleraMonitor(MXS_MONITOR *mon) GaleraMonitor::~GaleraMonitor() { hashtable_free(m_galera_nodes_info); - MXS_FREE(m_script); } // static @@ -204,9 +203,9 @@ json_t* GaleraMonitor::diagnostics_json() const json_object_set_new(rval, "use_priority", json_boolean(m_use_priority)); json_object_set_new(rval, "set_donor_nodes", json_boolean(m_set_donor_nodes)); - if (m_script) + if (!m_script.empty()) { - json_object_set_new(rval, "script", json_string(m_script)); + json_object_set_new(rval, "script", json_string(m_script.c_str())); } if (m_cluster_info.c_uuid) @@ -606,7 +605,7 @@ void GaleraMonitor::main() * After updating the status of all servers, check if monitor events * need to be launched. */ - mon_process_state_changes(m_monitor, m_script, m_events); + mon_process_state_changes(m_monitor, m_script.empty() ? NULL : m_script.c_str(), m_events); mon_hangup_failed_servers(m_monitor); diff --git a/server/modules/monitor/grmon/grmon.cc b/server/modules/monitor/grmon/grmon.cc index 87240189d..e5eb9a362 100644 --- a/server/modules/monitor/grmon/grmon.cc +++ b/server/modules/monitor/grmon/grmon.cc @@ -29,7 +29,6 @@ GRMon::GRMon(MXS_MONITOR* monitor) : MonitorInstance(monitor) , m_master(NULL) - , m_script(NULL) { } @@ -54,8 +53,6 @@ bool GRMon::has_sufficient_permissions() const void GRMon::configure(const MXS_CONFIG_PARAMETER* params) { - // TODO: Turn MonitorInstance::m_script into a std::string and remove GRMon::m_script - m_script = config_get_string(params, "script"); m_master = NULL; } diff --git a/server/modules/monitor/grmon/grmon.hh b/server/modules/monitor/grmon/grmon.hh index 75b26d23c..ac5c793bb 100644 --- a/server/modules/monitor/grmon/grmon.hh +++ b/server/modules/monitor/grmon/grmon.hh @@ -33,7 +33,6 @@ public: private: MXS_MONITORED_SERVER* m_master; /**< The master server */ - std::string m_script; GRMon(MXS_MONITOR* monitor); ~GRMon(); diff --git a/server/modules/monitor/mmmon/mmmon.cc b/server/modules/monitor/mmmon/mmmon.cc index ed7dd50e1..490498700 100644 --- a/server/modules/monitor/mmmon/mmmon.cc +++ b/server/modules/monitor/mmmon/mmmon.cc @@ -556,7 +556,7 @@ void MMMonitor::main() * After updating the status of all servers, check if monitor events * need to be launched. */ - mon_process_state_changes(mon, m_script, m_events); + mon_process_state_changes(mon, m_script.empty() ? NULL : m_script.c_str(), m_events); mon_hangup_failed_servers(mon); servers_status_current_to_pending(mon); diff --git a/server/modules/monitor/ndbclustermon/ndbclustermon.cc b/server/modules/monitor/ndbclustermon/ndbclustermon.cc index 73524686f..eeed2f4d8 100644 --- a/server/modules/monitor/ndbclustermon/ndbclustermon.cc +++ b/server/modules/monitor/ndbclustermon/ndbclustermon.cc @@ -310,7 +310,7 @@ void NDBCMonitor::main() * After updating the status of all servers, check if monitor events * need to be launched. */ - mon_process_state_changes(m_monitor, m_script, m_events); + mon_process_state_changes(m_monitor, m_script.empty() ? NULL : m_script.c_str(), m_events); mon_hangup_failed_servers(m_monitor); servers_status_current_to_pending(m_monitor);