Projects
Eulaceura:Mainline:GA
oeAware-manager
_service:obs_scm:0003-fix-coredump-when-process...
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File _service:obs_scm:0003-fix-coredump-when-process-exits.patch of Package oeAware-manager
From d6d5fe30da78917f3d32e670b79a8603ace76af4 Mon Sep 17 00:00:00 2001 From: fly_1997 <flylove7@outlook.com> Date: Mon, 8 Jul 2024 16:53:18 +0800 Subject: [PATCH 4/4] fix coredump when process exits --- src/plugin_mgr/instance_run_handler.cpp | 18 +++++++++++++++--- src/plugin_mgr/instance_run_handler.h | 3 ++- src/plugin_mgr/main.cpp | 18 +++++------------- src/plugin_mgr/plugin_manager.cpp | 18 ++++++++++++++++++ src/plugin_mgr/plugin_manager.h | 7 +++++++ 5 files changed, 47 insertions(+), 17 deletions(-) diff --git a/src/plugin_mgr/instance_run_handler.cpp b/src/plugin_mgr/instance_run_handler.cpp index 7f03f8f..70e3c33 100644 --- a/src/plugin_mgr/instance_run_handler.cpp +++ b/src/plugin_mgr/instance_run_handler.cpp @@ -107,8 +107,9 @@ void InstanceRunHandler::disable_instance(const std::string &name, bool force) { } } -void InstanceRunHandler::handle_instance() { +bool InstanceRunHandler::handle_message() { std::shared_ptr<InstanceRunMessage> msg; + bool shutdown = false; while(this->recv_queue_try_pop(msg)){ std::shared_ptr<Instance> instance = msg->get_instance(); switch (msg->get_type()){ @@ -120,9 +121,17 @@ void InstanceRunHandler::handle_instance() { disable_instance(instance->get_name(), true); break; } + case RunType::SHUTDOWN: { + shutdown = true; + break; + } } msg->notify_one(); + if (shutdown) { + return false; + } } + return true; } void InstanceRunHandler::change_instance_state(const std::string &name, std::vector<std::string> &deps, @@ -183,9 +192,12 @@ void InstanceRunHandler::schedule() { } void start(InstanceRunHandler *instance_run_handler) { - INFO("[PluginManager] instance schedule started!"); + INFO("[InstanceRunHandler] instance schedule started!"); while(true) { - instance_run_handler->handle_instance(); + if (!instance_run_handler->handle_message()) { + INFO("[InstanceRunHandler] instance schedule shutdown!"); + break; + } instance_run_handler->schedule(); usleep(instance_run_handler->get_cycle() * 1000); instance_run_handler->add_time(instance_run_handler->get_cycle()); diff --git a/src/plugin_mgr/instance_run_handler.h b/src/plugin_mgr/instance_run_handler.h index 64ddfa5..90cc60e 100644 --- a/src/plugin_mgr/instance_run_handler.h +++ b/src/plugin_mgr/instance_run_handler.h @@ -22,6 +22,7 @@ enum class RunType { /* Message from PluginManager. */ ENABLED, DISABLED, + SHUTDOWN, }; /* Message for communication between plugin manager and instance scheduling */ @@ -70,7 +71,7 @@ public: explicit InstanceRunHandler(MemoryStore &memory_store) : memory_store(memory_store), time(0), cycle(DEFAULT_CYCLE_SIZE) { } void run(); void schedule(); - void handle_instance(); + bool handle_message(); void set_cycle(int cycle) { this->cycle = cycle; } diff --git a/src/plugin_mgr/main.cpp b/src/plugin_mgr/main.cpp index 9add8ac..626aea9 100644 --- a/src/plugin_mgr/main.cpp +++ b/src/plugin_mgr/main.cpp @@ -22,20 +22,12 @@ void print_help() { } void signal_handler(int signum) { - auto &plugin_manager = PluginManager::get_instance(); - auto memory_store = plugin_manager.get_memory_store(); - auto all_plugins = memory_store.get_all_plugins(); - for (auto plugin : all_plugins) { - for (size_t i = 0; i < plugin->get_instance_len(); ++i) { - auto instance = plugin->get_instance(i); - if (!instance->get_enabled()) { - continue; - } - instance->get_interface()->disable(); - INFO("[PluginManager] " << instance->get_name() << " instance disabled."); - } + if (signum != SIGINT && signum != SIGTERM) { + ERROR("Unknown signal: " << signum); + exit(signum); } - exit(signum); + auto &plugin_manager = PluginManager::get_instance(); + plugin_manager.send_msg(Message(Opt::SHUTDOWN, MessageType::INTERNAL)); } int main(int argc, char **argv) { diff --git a/src/plugin_mgr/plugin_manager.cpp b/src/plugin_mgr/plugin_manager.cpp index c3ff8bf..b979859 100644 --- a/src/plugin_mgr/plugin_manager.cpp +++ b/src/plugin_mgr/plugin_manager.cpp @@ -336,6 +336,23 @@ void PluginManager::pre_load() { pre_enable(); } +void PluginManager::exit() { + auto all_plugins = memory_store.get_all_plugins(); + auto msg = std::make_shared<InstanceRunMessage>(RunType::SHUTDOWN, nullptr); + send_msg_to_instance_run_handler(msg); + msg->wait(); + for (auto plugin : all_plugins) { + for (size_t i = 0; i < plugin->get_instance_len(); ++i) { + auto instance = plugin->get_instance(i); + if (!instance->get_enabled()) { + continue; + } + instance->get_interface()->disable(); + INFO("[PluginManager] " << instance->get_name() << " instance disabled."); + } + } +} + const void* PluginManager::get_data_buffer(const std::string &name) { std::shared_ptr<Instance> instance = memory_store.get_instance(name); return instance->get_interface()->get_ring_buf(); @@ -553,5 +570,6 @@ int PluginManager::run() { if (msg.get_type() == MessageType::EXTERNAL) res_msg->push(res); } + exit(); return 0; } diff --git a/src/plugin_mgr/plugin_manager.h b/src/plugin_mgr/plugin_manager.h index b7c04fe..c3f6f69 100644 --- a/src/plugin_mgr/plugin_manager.h +++ b/src/plugin_mgr/plugin_manager.h @@ -32,6 +32,10 @@ public: const MemoryStore& get_memory_store() { return this->memory_store; } + void exit(); + void send_msg(const Message &msg) { + handler_msg->push(msg); + } const void* get_data_buffer(const std::string &name); private: PluginManager() { } @@ -57,6 +61,9 @@ private: void update_instance_state(); bool end_with(const std::string &s, const std::string &ending); std::string get_plugin_in_dir(const std::string &path); + void send_msg_to_instance_run_handler(std::shared_ptr<InstanceRunMessage> msg) { + instance_run_handler->recv_queue_push(msg); + } private: std::unique_ptr<InstanceRunHandler> instance_run_handler; std::shared_ptr<Config> config; -- 2.33.0
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.
浙ICP备2022010568号-2