fix spec file and some bugs
(cherry picked from commit ca6063d6790f27ef39fb17c5ec7e917c99d83dce)
This commit is contained in:
parent
571ff839a7
commit
9b1ab30deb
1080
0001-fix-remove-plugin-bug-and-refactor.patch
Normal file
1080
0001-fix-remove-plugin-bug-and-refactor.patch
Normal file
File diff suppressed because it is too large
Load Diff
1599
0002-add-error-code-and-replace-raw-poniters-with-smart-p.patch
Normal file
1599
0002-add-error-code-and-replace-raw-poniters-with-smart-p.patch
Normal file
File diff suppressed because it is too large
Load Diff
1034
0003-add-client-error-description-extract-class-and-fix-b.patch
Normal file
1034
0003-add-client-error-description-extract-class-and-fix-b.patch
Normal file
File diff suppressed because it is too large
Load Diff
200
0004-fix-auto-enable-error-and-check-plugin-list-config.patch
Normal file
200
0004-fix-auto-enable-error-and-check-plugin-list-config.patch
Normal file
@ -0,0 +1,200 @@
|
||||
From 7ff05329ac299727fc2be5d7f1a92a4e3b0bdd43 Mon Sep 17 00:00:00 2001
|
||||
From: fly_1997 <flylove7@outlook.com>
|
||||
Date: Mon, 29 Apr 2024 17:31:44 +0800
|
||||
Subject: [PATCH 4/4] fix auto enable error and check plugin list config
|
||||
|
||||
---
|
||||
oeaware.service | 2 +-
|
||||
src/client/arg_parse.cpp | 7 ++++---
|
||||
src/common/utils.cpp | 34 ++++++++++++++++++-------------
|
||||
src/plugin_mgr/config.cpp | 21 ++++++++++++++-----
|
||||
src/plugin_mgr/config.h | 3 +++
|
||||
src/plugin_mgr/plugin_manager.cpp | 11 +++++++++-
|
||||
6 files changed, 54 insertions(+), 24 deletions(-)
|
||||
|
||||
diff --git a/oeaware.service b/oeaware.service
|
||||
index 3ab4b69..b321530 100644
|
||||
--- a/oeaware.service
|
||||
+++ b/oeaware.service
|
||||
@@ -5,7 +5,7 @@ After=network.target
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/bin/oeaware /etc/oeAware/config.yaml
|
||||
-ExecStop=kill -9 $MAINPID
|
||||
+ExecStop=kill $MAINPID && sleep 5 && kill -9 $MAINPID
|
||||
Restart=on-failure
|
||||
RestartSec=1
|
||||
RemainAfterExit=yes
|
||||
diff --git a/src/client/arg_parse.cpp b/src/client/arg_parse.cpp
|
||||
index cbf0b8e..70fcd4a 100644
|
||||
--- a/src/client/arg_parse.cpp
|
||||
+++ b/src/client/arg_parse.cpp
|
||||
@@ -30,6 +30,7 @@ const struct option ArgParse::long_options[] = {
|
||||
|
||||
void ArgParse::arg_error(const std::string &msg) {
|
||||
std::cerr << "oeawarectl: " << msg << "\n";
|
||||
+ print_help();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -42,7 +43,7 @@ void ArgParse::set_arg(char *_arg) {
|
||||
}
|
||||
|
||||
void ArgParse::print_help() {
|
||||
- std::cout << "oeawarectl [options]...\n"
|
||||
+ std::cout << "usage: oeawarectl [options]...\n"
|
||||
" options\n"
|
||||
" -l|--load [plugin] load plugin and need plugin type.\n"
|
||||
" -t|--type [plugin_type] assign plugin type. there are three types:\n"
|
||||
@@ -76,12 +77,12 @@ int ArgParse::init(int argc, char *argv[]) {
|
||||
help = true;
|
||||
break;
|
||||
case '?':
|
||||
- arg_error("unknown option. See --help.");
|
||||
+ arg_error("unknown option.");
|
||||
return -1;
|
||||
default: {
|
||||
if (opt == 'l' || opt == 'r' || opt == 'q' || opt == 'Q' || opt == 'e' || opt == 'd' || opt == 'L' || opt == 'i') {
|
||||
if (cmd != -1) {
|
||||
- arg_error("invalid option. See --help.\n");
|
||||
+ arg_error("invalid option.");
|
||||
return -1;
|
||||
}
|
||||
cmd = opt;
|
||||
diff --git a/src/common/utils.cpp b/src/common/utils.cpp
|
||||
index 9435a5b..f2c277d 100644
|
||||
--- a/src/common/utils.cpp
|
||||
+++ b/src/common/utils.cpp
|
||||
@@ -23,28 +23,34 @@ static void curl_set_opt(CURL *curl, const std::string &url, FILE *file) {
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, file);
|
||||
|
||||
}
|
||||
+static bool curl_handle(CURL *curl, const std::string &url, const std::string &path) {
|
||||
+ FILE *file = fopen(path.c_str(), "wb");
|
||||
+ if (file == nullptr) {
|
||||
+ return false;
|
||||
+ }
|
||||
+ curl_set_opt(curl, url, file);
|
||||
+ CURLcode res = curl_easy_perform(curl);
|
||||
+ long http_code = 0;
|
||||
+ curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
|
||||
+ fclose(file);
|
||||
+ if (res == CURLE_OK && http_code >= 200 && http_code < 300) {
|
||||
+ return true;
|
||||
+ }
|
||||
+ return false;
|
||||
+}
|
||||
+
|
||||
// Downloads file from the specified url to the path.
|
||||
bool download(const std::string &url, const std::string &path) {
|
||||
CURL *curl = nullptr;
|
||||
- CURLcode res;
|
||||
- bool ok = true;
|
||||
+ bool ret = true;
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
curl = curl_easy_init();
|
||||
if (curl) {
|
||||
- FILE *file = fopen(path.c_str(), "wb");
|
||||
- if (file == nullptr) {
|
||||
- return false;
|
||||
- }
|
||||
- curl_set_opt(curl, url, file);
|
||||
- res = curl_easy_perform(curl);
|
||||
- fclose(file);
|
||||
- if (res != CURLE_OK) {
|
||||
- ok = false;
|
||||
- }
|
||||
+ if (!curl_handle(curl, url, path)) ret = false;
|
||||
} else {
|
||||
- ok = false;
|
||||
+ ret = false;
|
||||
}
|
||||
curl_global_cleanup();
|
||||
curl_easy_cleanup(curl);
|
||||
- return ok;
|
||||
+ return ret;
|
||||
}
|
||||
\ No newline at end of file
|
||||
diff --git a/src/plugin_mgr/config.cpp b/src/plugin_mgr/config.cpp
|
||||
index 1de5a34..3c76e8e 100644
|
||||
--- a/src/plugin_mgr/config.cpp
|
||||
+++ b/src/plugin_mgr/config.cpp
|
||||
@@ -30,6 +30,18 @@ bool create_dir(const std::string &path) {
|
||||
return true;
|
||||
}
|
||||
|
||||
+bool check_plugin_list(YAML::Node plugin_list_item) {
|
||||
+ if (plugin_list_item["name"].IsNull()) {
|
||||
+ std::cerr << "Warn: null name in plugin_list.\n";
|
||||
+ return false;
|
||||
+ }
|
||||
+ if (plugin_list_item["url"].IsNull()) {
|
||||
+ std::cerr << "Warn: null url in plugin_list.\n";
|
||||
+ return false;
|
||||
+ }
|
||||
+ return true;
|
||||
+}
|
||||
+
|
||||
bool Config::load(const std::string path) {
|
||||
YAML::Node node;
|
||||
struct stat buffer;
|
||||
@@ -49,16 +61,15 @@ bool Config::load(const std::string path) {
|
||||
YAML::Node plugin_list = node["plugin_list"];
|
||||
if (plugin_list.IsSequence()) {
|
||||
for (int i = 0; i < plugin_list.size(); ++i) {
|
||||
+ if (!check_plugin_list(plugin_list[i])){
|
||||
+ continue;
|
||||
+ }
|
||||
std::string name = plugin_list[i]["name"].as<std::string>();
|
||||
std::string description = plugin_list[i]["description"].as<std::string>();
|
||||
std::string url = plugin_list[i]["url"].as<std::string>();
|
||||
PluginInfo info(name, description, url);
|
||||
- if (name.empty()) {
|
||||
- std::cerr << "Warn: " << name << " url is empty.\n";
|
||||
- continue;
|
||||
- }
|
||||
if (this->plugin_list.count(name)) {
|
||||
- std::cerr << "Warn: duplicate " << name << " in plugin_list.\n";
|
||||
+ std::cerr << "Warn: duplicate \"" << name << "\" in plugin_list.\n";
|
||||
continue;
|
||||
}
|
||||
this->plugin_list.insert(std::make_pair(name, info));
|
||||
diff --git a/src/plugin_mgr/config.h b/src/plugin_mgr/config.h
|
||||
index 16c7871..5ab7672 100644
|
||||
--- a/src/plugin_mgr/config.h
|
||||
+++ b/src/plugin_mgr/config.h
|
||||
@@ -65,6 +65,9 @@ public:
|
||||
size_t get_instance_size() const {
|
||||
return this->instance.size();
|
||||
}
|
||||
+ std::string get_instance_name(int i) {
|
||||
+ return this->instance[i];
|
||||
+ }
|
||||
std::string get_name() const {
|
||||
return this->name;
|
||||
}
|
||||
diff --git a/src/plugin_mgr/plugin_manager.cpp b/src/plugin_mgr/plugin_manager.cpp
|
||||
index c9981ef..0826a60 100644
|
||||
--- a/src/plugin_mgr/plugin_manager.cpp
|
||||
+++ b/src/plugin_mgr/plugin_manager.cpp
|
||||
@@ -348,7 +348,16 @@ void PluginManager::pre_enable() {
|
||||
}
|
||||
std::shared_ptr<Plugin> plugin = memory_store.get_plugin(name);
|
||||
for (int j = 0; j < plugin->get_instance_len(); ++j) {
|
||||
- instance_enabled(plugin->get_instance(i)->get_name());
|
||||
+ instance_enabled(plugin->get_instance(j)->get_name());
|
||||
+ }
|
||||
+ } else {
|
||||
+ for (int j = 0; j < item.get_instance_size(); ++j) {
|
||||
+ std::string name = item.get_instance_name(j);
|
||||
+ if (!memory_store.is_instance_exist(name)) {
|
||||
+ WARN("[PluginManager] instance " << name << " cannot be enabled, because it does not exist.");
|
||||
+ continue;
|
||||
+ }
|
||||
+ instance_enabled(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
--
|
||||
2.33.0
|
||||
|
||||
@ -1,10 +1,14 @@
|
||||
Name: oeAware-manager
|
||||
Version: v1.0.0
|
||||
Release: 2
|
||||
Release: 3
|
||||
Summary: OeAware server and client
|
||||
License: MulanPSL2
|
||||
URL: https://gitee.com/openeuler/%{name}
|
||||
Source0: %{name}-%{version}.tar.gz
|
||||
Patch1: 0001-fix-remove-plugin-bug-and-refactor.patch
|
||||
Patch2: 0002-add-error-code-and-replace-raw-poniters-with-smart-p.patch
|
||||
Patch3: 0003-add-client-error-description-extract-class-and-fix-b.patch
|
||||
Patch4: 0004-fix-auto-enable-error-and-check-plugin-list-config.patch
|
||||
|
||||
BuildRequires: cmake make gcc-c++
|
||||
BuildRequires: boost-devel
|
||||
@ -30,21 +34,23 @@ cmake ..
|
||||
make %{?_smp_mflags}
|
||||
|
||||
%install
|
||||
install -D -m 0770 build/src/plugin_mgr/oeAware %{buildroot}%{_bindir}/oeaware
|
||||
install -D -m 0770 build/src/client/oeawarectl %{buildroot}%{_bindir}/oeawarectl
|
||||
install -D -m 0750 build/src/plugin_mgr/oeaware %{buildroot}%{_bindir}/oeaware
|
||||
install -D -m 0750 build/src/client/oeawarectl %{buildroot}%{_bindir}/oeawarectl
|
||||
install -D -m 0640 config.yaml %{buildroot}%{_sysconfdir}/oeAware/config.yaml
|
||||
install -D -p -m 0644 oeAware.service %{buildroot}%{_unitdir}/oeAware.service
|
||||
install -D -p -m 0644 oeaware.service %{buildroot}%{_unitdir}/oeaware.service
|
||||
|
||||
%files
|
||||
%attr(0770, root, root) %{_bindir}/oeaware
|
||||
%attr(0770, root, root) %{_bindir}/oeawarectl
|
||||
%attr(0750, root, root) %{_bindir}/oeaware
|
||||
%attr(0750, root, root) %{_bindir}/oeawarectl
|
||||
%attr(0640, root, root) %{_sysconfdir}/oeAware/config.yaml
|
||||
%attr(0644, root, root) %{_unitdir}/oeAware.service
|
||||
%attr(0644, root, root) %{_unitdir}/oeaware.service
|
||||
|
||||
%changelog
|
||||
* Mon Apr 29 2024 fly_1997 <flylove7@outlook.com> -v1.0.0-3
|
||||
- add error description, refactor, and fix bugs
|
||||
|
||||
* Sun Apr 28 2024 huangwenhua <huangwenhua@kylinos.cn> -v1.0.0-2
|
||||
- Add Requires:graphviz
|
||||
|
||||
* Thu Apr 18 2024 fly_1997 <flylove7@outlook.com> -v1.0.0-1
|
||||
- Package init
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user