From f96a7201cf0d9d010f7c0202af60ac40bd55911a Mon Sep 17 00:00:00 2001 From: Thulinma Date: Thu, 30 May 2024 12:56:59 +0200 Subject: [PATCH] =?UTF-8?q?Do=20the=20thing=E2=84=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/config.cpp | 12 ++++++++++-- lib/config.h | 1 + src/controller/controller.cpp | 2 ++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/config.cpp b/lib/config.cpp index d2bc7392..790d1844 100644 --- a/lib/config.cpp +++ b/lib/config.cpp @@ -576,6 +576,11 @@ void Util::Config::activate(){ is_active = true; } +tthread::mutex * mutabort = 0; +void Util::Config::setMutexAborter(void * mutex){ + mutabort = (tthread::mutex*)mutex; +} + /// Basic signal handler. Sets is_active to false if it receives /// a SIGINT, SIGHUP or SIGTERM signal, reaps children for the SIGCHLD /// signal, and ignores all other signals. @@ -584,8 +589,11 @@ void Util::Config::signal_handler(int signum, siginfo_t *sigInfo, void *ignore){ case SIGINT: // these three signals will set is_active to false. case SIGHUP: case SIGTERM: - if (serv_sock_pointer){serv_sock_pointer->close();} - if (stdin){fclose(stdin);} + if (!mutabort || mutabort->try_lock()){ + if (serv_sock_pointer){serv_sock_pointer->close();} + if (stdin){fclose(stdin);} + if (mutabort){mutabort->unlock();} + } #if DEBUG >= DLVL_DEVEL static int ctr = 0; if (!is_active && ++ctr > 4){BACKTRACE;} diff --git a/lib/config.h b/lib/config.h index d5b66ce6..819f9e63 100644 --- a/lib/config.h +++ b/lib/config.h @@ -36,6 +36,7 @@ namespace Util{ static void signal_handler(int signum, siginfo_t *sigInfo, void *ignore); public: + static void setMutexAborter(void * mutex); // variables static bool is_active; ///< Set to true by activate(), set to false by the signal handler. static bool is_restarting; ///< Set to true when restarting, set to false on boot. diff --git a/src/controller/controller.cpp b/src/controller/controller.cpp index 02cfc2e8..4975836e 100644 --- a/src/controller/controller.cpp +++ b/src/controller/controller.cpp @@ -403,6 +403,7 @@ int main_loop(int argc, char **argv){ Controller::updateBandwidthConfig(); createAccount(Controller::conf.getString("account")); Controller::conf.activate(); // activate early, so threads aren't killed. + Controller::conf.setMutexAborter(&Controller::configMutex); #if !defined(__CYGWIN__) && !defined(_WIN32) { @@ -630,6 +631,7 @@ int main(int argc, char **argv){ Controller::conf = Util::Config(argv[0]); Util::Config::binaryType = Util::CONTROLLER; Controller::conf.activate(); + Controller::conf.setMutexAborter(&Controller::configMutex); if (getenv("ATHEIST")){return main_loop(argc, argv);} uint64_t reTimer = 0; while (Controller::conf.is_active){