From e93c2abbfa54d7115abb46f4caf5689dac75db0f Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 7 Oct 2021 08:33:06 +0900 Subject: [PATCH] Use destructor attribute for disposing thread The rpc-port library can be loaded and unloaded using dlopen() and dlclose() in the runtime. In this case, the process has crashed by the thread of the rpc-port library. Before unloading the library, the thread has to be terminated. This patch uses destructor attribute to terminate the thread appropriately before unloading the library is finished. Change-Id: I2338a4419f02fb67dff042fd308ba1d590bf0ac3 Signed-off-by: Hwankyu Jhun --- src/debug-port-internal.cc | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/debug-port-internal.cc b/src/debug-port-internal.cc index ddfd930..2f3219e 100644 --- a/src/debug-port-internal.cc +++ b/src/debug-port-internal.cc @@ -25,19 +25,26 @@ #include "debug-port-internal.hh" #include "log-private.hh" +#undef RPC_DTOR +#define RPC_DTOR __attribute__ ((destructor)) + namespace rpc_port { namespace internal { namespace { const char PATH_RPC_PORT_UTIL_SOCK[] = "/run/aul/daemons/.rpc-port-util-sock"; + +RPC_DTOR void DebugPortDtor() { + DebugPort::GetInst()->Dispose(); +} + } // namespace std::atomic DebugPort::inst_; std::mutex DebugPort::mutex_; DebugPort::~DebugPort() { - if (!disposed_) - Dispose(); + Dispose(); } DebugPort* DebugPort::GetInst() { @@ -59,6 +66,10 @@ DebugPort* DebugPort::GetInst() { } void DebugPort::Dispose() { + std::lock_guard lock(GetMutex()); + if (disposed_) + return; + Unwatch(); JoinThread(); disposed_ = true; -- 2.7.4