From 72eb21bbca8600bc2bf4428878c52e60884bfd48 Mon Sep 17 00:00:00 2001 From: thunder2 Date: Wed, 29 Dec 2021 17:56:11 +0100 Subject: [PATCH 1/2] Use shutdownSync instead of shutdown in TorManager::run to stop tor --- libretroshare/src/tor/TorManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libretroshare/src/tor/TorManager.cpp b/libretroshare/src/tor/TorManager.cpp index bd768af68..628f35733 100644 --- a/libretroshare/src/tor/TorManager.cpp +++ b/libretroshare/src/tor/TorManager.cpp @@ -462,7 +462,7 @@ void TorManager::run() std::this_thread::sleep_for(std::chrono::milliseconds(50)); } - d->control->shutdown(); + d->control->shutdownSync(); d->process->stop(); if(rsEvents) From 460dbdcdc82499317ff5d500d89290040d995c5e Mon Sep 17 00:00:00 2001 From: thunder2 Date: Wed, 29 Dec 2021 17:23:25 +0100 Subject: [PATCH 2/2] Added shutdown of tor management threads --- libretroshare/src/retroshare/rstor.h | 6 ++++++ libretroshare/src/tor/TorManager.cpp | 15 +++++++++++++-- retroshare-gui/src/main.cpp | 4 ++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/libretroshare/src/retroshare/rstor.h b/libretroshare/src/retroshare/rstor.h index 0ae966a7e..8eaa4a352 100644 --- a/libretroshare/src/retroshare/rstor.h +++ b/libretroshare/src/retroshare/rstor.h @@ -141,6 +141,12 @@ public: */ static bool start(); + /*! + * \brief stop + * Stop the Tor management threads. + */ + static void stop(); + /*! * \brief getHiddenServiceInfo * Gets information about the hidden service setup by RS to run. diff --git a/libretroshare/src/tor/TorManager.cpp b/libretroshare/src/tor/TorManager.cpp index 628f35733..ff2d53ced 100644 --- a/libretroshare/src/tor/TorManager.cpp +++ b/libretroshare/src/tor/TorManager.cpp @@ -53,6 +53,8 @@ using namespace Tor; +static TorManager *rsTor = nullptr; + namespace Tor { @@ -840,6 +842,17 @@ bool RsTor::start() return instance()->startTorManager(); } +void RsTor::stop() +{ + if (rsTor) { + if (rsTor->isRunning()) { + rsTor->fullstop(); + } + delete(rsTor); + rsTor= nullptr; + } +} + void RsTor::setTorDataDirectory(const std::string& dir) { instance()->setTorDataDirectory(dir); @@ -855,8 +868,6 @@ TorManager *RsTor::instance() assert(getpid() == syscall(SYS_gettid));// make sure we're not in a thread #endif - static TorManager *rsTor = nullptr; - if(rsTor == nullptr) rsTor = new TorManager; diff --git a/retroshare-gui/src/main.cpp b/retroshare-gui/src/main.cpp index d8818db0c..82d78d2b2 100644 --- a/retroshare-gui/src/main.cpp +++ b/retroshare-gui/src/main.cpp @@ -591,6 +591,10 @@ feenableexcept(FE_INVALID | FE_DIVBYZERO); RsGxsUpdateBroadcast::cleanup(); #endif + if (is_auto_tor) { + RsTor::stop(); + } + RsControl::instance()->rsGlobalShutDown(); delete(soundManager);