If a process contained a log agent was forked into another process,
both processes shared the created sockets. If a process exit,
the destructor of log agent will be invoked and all shared resources
will be cleaned. It led the remain process can't write logs anymore.
This ticket don't allow the child process to clean the shared resources,
only the process constructed the log agent can clean it.
---
 src/log/agent/lga_agent.cc | 9 ++++++++-
 src/log/agent/lga_agent.h  | 2 ++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/log/agent/lga_agent.cc b/src/log/agent/lga_agent.cc
index a0f720ff3..7bb6c1096 100644
--- a/src/log/agent/lga_agent.cc
+++ b/src/log/agent/lga_agent.cc
@@ -137,6 +137,7 @@ ScopeData::~ScopeData() {
 
//------------------------------------------------------------------------------
 LogAgent::LogAgent() {
   client_list_.clear();
+  pid = getpid();
   lga_proc_mng_start();
   // There is high risk of calling one @LogClient method
   // in the body of other @LogClient methods, such case would cause deadlock
@@ -168,6 +169,12 @@ LogAgent::~LogAgent() {
   TRACE_ENTER();
   ScopeLock scopeLock(mutex_);
 
+  if (pid != getpid()) {
+    LOG_WA("pid %d: Call the destructor of log agent in a process which didn't"
+           " create it so don't clean the shared resources", getpid());
+    TRACE_LEAVE();
+    return;
+  }
   lga_proc_mng_stop();
   stop_recovery2_thread();
   lga_shutdown();
@@ -758,7 +765,7 @@ SaAisErrorT LogAgent::saLogFinalize(SaLogHandleT logHandle) 
{
     }
   }
 
-  if (lga_get_number_of_user() == 0) {
+  if (pid == getpid() && lga_get_number_of_user() == 0) {
     // Stop recovery thread if it's running
     stop_recovery2_thread();
     // Shutdown the agent
diff --git a/src/log/agent/lga_agent.h b/src/log/agent/lga_agent.h
index 957adc716..0808cfdb9 100644
--- a/src/log/agent/lga_agent.h
+++ b/src/log/agent/lga_agent.h
@@ -291,6 +291,8 @@ class LogAgent {
   NCS_SEL_OBJ init_clm_status_sel_;
   // Log server sync params
   NCS_SEL_OBJ log_server_up_sel_;
+  // Id of process constructed this object
+  pid_t pid;
 
   DELETE_COPY_AND_MOVE_OPERATORS(LogAgent);
 };
-- 
2.25.1



_______________________________________________
Opensaf-devel mailing list
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to