From 122b4998d6395a645877a9aa7ef456dd9c73c00a Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Thu, 27 Feb 2025 14:35:37 -0600 Subject: [PATCH] added signal handler --- repertory/repertory/src/ui/handlers.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/repertory/repertory/src/ui/handlers.cpp b/repertory/repertory/src/ui/handlers.cpp index 95a12008..f2ce3b56 100644 --- a/repertory/repertory/src/ui/handlers.cpp +++ b/repertory/repertory/src/ui/handlers.cpp @@ -70,8 +70,16 @@ handlers::handlers(mgmt_app_config *config, httplib::Server *server) event_system::instance().start(); - static auto *this_server{server_}; - static const auto quit_handler = [](int /* sig */) { this_server->stop(); }; + static std::atomic this_server{server_}; + static const auto quit_handler = [](int /* sig */) { + auto *ptr = this_server.load(); + if (ptr == nullptr) { + return; + } + + this_server = nullptr; + ptr->stop(); + }; std::signal(SIGINT, quit_handler); #if !defined(_WIN32) @@ -80,6 +88,7 @@ handlers::handlers(mgmt_app_config *config, httplib::Server *server) std::signal(SIGTERM, quit_handler); server_->listen("127.0.0.1", config_->get_api_port()); + this_server = nullptr; } handlers::~handlers() { event_system::instance().stop(); }