!59 [sync] PR-54: fix coredump and add automatic startup based on the version
From: @openeuler-sync-bot Reviewed-by: @ksana123 Signed-off-by: @ksana123
This commit is contained in:
commit
b8f065d1e8
@ -0,0 +1,30 @@
|
||||
From 54c5b50eb19467d32d83a85478f468dff52b69e6 Mon Sep 17 00:00:00 2001
|
||||
From: Zhao Mengmeng <zhaomengmeng@kylinos.cn>
|
||||
Date: Thu, 27 Jun 2024 13:45:00 +0800
|
||||
Subject: [PATCH 1/4] plugin_mgr: logger: apppend to logfile rather than
|
||||
truncate
|
||||
|
||||
In log4cplus, the default openmode for Class FileAppender is
|
||||
std::ios_base::trunc, which cause the log file be cleared after
|
||||
each `systemctl restart oeaware.service`. Fix this by setting
|
||||
openmode to std::ios_base::app.
|
||||
---
|
||||
src/plugin_mgr/logger.cpp | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/plugin_mgr/logger.cpp b/src/plugin_mgr/logger.cpp
|
||||
index af39583..378075c 100644
|
||||
--- a/src/plugin_mgr/logger.cpp
|
||||
+++ b/src/plugin_mgr/logger.cpp
|
||||
@@ -27,7 +27,7 @@ Logger::Logger() {
|
||||
}
|
||||
|
||||
void Logger::init(std::shared_ptr<Config> config) {
|
||||
- log4cplus::SharedAppenderPtr appender(new log4cplus::FileAppender(config->get_log_path() + "/server.log"));
|
||||
+ log4cplus::SharedAppenderPtr appender(new log4cplus::FileAppender(config->get_log_path() + "/server.log", std::ios_base::app));
|
||||
appender->setName("file");
|
||||
log4cplus::tstring pattern = LOG4CPLUS_TEXT("%D{%m/%d/%y %H:%M:%S} [%t] %-5p %c - %m"
|
||||
#ifdef OEAWARE_DEBUG
|
||||
--
|
||||
2.33.0
|
||||
|
||||
@ -0,0 +1,26 @@
|
||||
From ed8c8d44f05f7fd2160252cbe1b2d10cbd6000cf Mon Sep 17 00:00:00 2001
|
||||
From: zhoukaiqi <zhoukaiqi@huawei.com>
|
||||
Date: Sat, 6 Jul 2024 14:34:24 +0800
|
||||
Subject: [PATCH 3/4] fix threads are still bound after systemctl stop oeaware
|
||||
|
||||
---
|
||||
src/plugin_mgr/main.cpp | 3 ++-
|
||||
1 file changed, 2 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/plugin_mgr/main.cpp b/src/plugin_mgr/main.cpp
|
||||
index 5cfb020..9add8ac 100644
|
||||
--- a/src/plugin_mgr/main.cpp
|
||||
+++ b/src/plugin_mgr/main.cpp
|
||||
@@ -39,7 +39,8 @@ void signal_handler(int signum) {
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
- signal(SIGINT, signal_handler);
|
||||
+ signal(SIGINT, signal_handler); // ctrl + c
|
||||
+ signal(SIGTERM, signal_handler); // systemctl stop
|
||||
std::shared_ptr<Config> config = std::make_shared<Config>();
|
||||
if (argc < 2) {
|
||||
ERROR("System need a argument!");
|
||||
--
|
||||
2.33.0
|
||||
|
||||
175
0003-fix-coredump-when-process-exits.patch
Normal file
175
0003-fix-coredump-when-process-exits.patch
Normal file
@ -0,0 +1,175 @@
|
||||
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
|
||||
|
||||
@ -1,10 +1,13 @@
|
||||
Name: oeAware-manager
|
||||
Version: v1.0.2
|
||||
Release: 2
|
||||
Release: 3
|
||||
Summary: OeAware server and client
|
||||
License: MulanPSL2
|
||||
URL: https://gitee.com/openeuler/%{name}
|
||||
Source0: %{name}-%{version}.tar.gz
|
||||
Patch1: 0001-plugin_mgr-logger-apppend-to-logfile-rather-than-tru.patch
|
||||
Patch2: 0002-fix-threads-are-still-bound-after-systemctl-stop-oea.patch
|
||||
Patch3: 0003-fix-coredump-when-process-exits.patch
|
||||
|
||||
BuildRequires: cmake make gcc-c++
|
||||
BuildRequires: boost-devel
|
||||
@ -41,7 +44,12 @@ install -D -p -m 0644 oeaware.service %{buildroot}%{_unitdir}/oeaware.service
|
||||
|
||||
%post
|
||||
systemctl start oeaware.service
|
||||
systemctl enable oeaware.service
|
||||
|
||||
%posttrans
|
||||
. /etc/os-release || :
|
||||
if [ "${VERSION}" == "22.03 (LTS-SP4)" ]; then
|
||||
systemctl enable oeaware.service
|
||||
fi
|
||||
|
||||
%files
|
||||
%attr(0750, root, root) %{_bindir}/oeaware
|
||||
@ -50,6 +58,11 @@ systemctl enable oeaware.service
|
||||
%attr(0644, root, root) %{_unitdir}/oeaware.service
|
||||
|
||||
%changelog
|
||||
* Mon Jul 8 2024 fly_1997 <flylove7@outlook.com> -v1.0.2-3
|
||||
- add automatic startup based on the version
|
||||
- fix coredump when process exits
|
||||
- modify logger mode to append
|
||||
|
||||
* Thu Jun 27 2024 fly_1997 <flylove7@outlook.com> -v1.0.2-2
|
||||
- add enable automatic startup
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user