]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1627] make CommunicationState::startHeartbeat thread safe
authorRazvan Becheriu <razvan@isc.org>
Fri, 15 Jan 2021 11:23:31 +0000 (13:23 +0200)
committerRazvan Becheriu <razvan@isc.org>
Mon, 25 Jan 2021 11:38:21 +0000 (11:38 +0000)
src/hooks/dhcp/high_availability/communication_state.cc
src/hooks/dhcp/high_availability/communication_state.h
src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc
src/lib/testutils/dhcp_test_lib.sh.in

index d1fe6e1247422498e6f692b5c549b4bcdd3c8754..9989dffa249d98a6b9e66a3c9b40ab3409d34a44 100644 (file)
@@ -112,7 +112,12 @@ CommunicationState::setPartnerScopes(ConstElementPtr new_scopes) {
 void
 CommunicationState::startHeartbeat(const long interval,
                                    const std::function<void()>& heartbeat_impl) {
-    startHeartbeatInternal(interval, heartbeat_impl);
+    if (MultiThreadingMgr::instance().getMode()) {
+        std::lock_guard<std::mutex> lk(*mutex_);
+        startHeartbeatInternal(interval, heartbeat_impl);
+    } else {
+        startHeartbeatInternal(interval, heartbeat_impl);
+    }
 }
 
 void
@@ -158,6 +163,16 @@ CommunicationState::startHeartbeatInternal(const long interval,
 
 void
 CommunicationState::stopHeartbeat() {
+    if (MultiThreadingMgr::instance().getMode()) {
+        std::lock_guard<std::mutex> lk(*mutex_);
+        stopHeartbeatInternal();
+    } else {
+        stopHeartbeatInternal();
+    }
+}
+
+void
+CommunicationState::stopHeartbeatInternal() {
     if (timer_) {
         timer_->cancel();
         timer_.reset();
index b78d192b62c5584ed2e31249def4d8b77a88d5a9..43445eaee55875c8777295998412315f99270f03 100644 (file)
@@ -131,6 +131,9 @@ public:
     void startHeartbeat(const long interval,
                         const std::function<void()>& heartbeat_impl);
 
+    /// @brief Stops recurring heartbeat.
+    void stopHeartbeat();
+
 protected:
 
     /// @brief Starts recurring heartbeat.
@@ -141,10 +144,10 @@ protected:
     void startHeartbeatInternal(const long interval = 0,
                                 const std::function<void()>& heartbeat_impl = 0);
 
-public:
-
     /// @brief Stops recurring heartbeat.
-    void stopHeartbeat();
+    void stopHeartbeatInternal();
+
+public:
 
     /// @brief Checks if recurring heartbeat is running.
     ///
index 819e80f4e897b3b7652e5f56b7459159599b97bb..c5e29f273ffa935146344ef9c5faee47f1bfc8bd 100644 (file)
@@ -513,7 +513,7 @@ MySqlConfigBackendImpl::getOptionDefs(const int index,
 void
 MySqlConfigBackendImpl::createUpdateOptionDef(const db::ServerSelector& server_selector,
                                               const OptionDefinitionPtr& option_def,
-                                              const std::string& space,
+                                              const std::string& /*space*/,
                                               const int& /*get_option_def_code_space*/,
                                               const int& insert_option_def,
                                               const int& update_option_def,
index 77711488df26fc57f5e13a21a4a92015c792a860..9e182671750c8419f940cc6c87db857cdc977f89 100644 (file)
@@ -440,8 +440,8 @@ get_pid() {
     _GET_PIDS_NUM=0
 
     # If the PID file exists, get the PID and see if the process is alive.
-    if [ -e "${abs_pidfile_path}" ]; then
-        pid=$(cat "${abs_pidfile_path}")
+    pid=$(cat "${abs_pidfile_path}" || true)
+    if test -n "${pid}"; then
         if kill -0 "${pid}" > /dev/null 2>&1; then
             _GET_PID=${pid}
             _GET_PIDS_NUM=1