diff --git a/Use-malloc-to-allocate-memory-as-much-as-possible.patch b/Use-malloc-to-allocate-memory-as-much-as-possible.patch new file mode 100644 index 0000000000000000000000000000000000000000..39d7ec746586b0341a8ede3d3b3f89eb3e4b1ae9 --- /dev/null +++ b/Use-malloc-to-allocate-memory-as-much-as-possible.patch @@ -0,0 +1,149 @@ +From 87f20a47f32adc03464fac4eff4c8450fcf5a45e Mon Sep 17 00:00:00 2001 +From: shixuantong +Date: Thu, 3 Apr 2025 10:01:15 +0800 +Subject: [PATCH] Use malloc to allocate memory as much as possible + +--- + src/libs/libxalarm/register_xalarm.c | 34 ++++++++++--------- + .../sentry_msg_monitor/sentry_msg_monitor.c | 20 +++++++++-- + 2 files changed, 36 insertions(+), 18 deletions(-) + +diff --git a/src/libs/libxalarm/register_xalarm.c b/src/libs/libxalarm/register_xalarm.c +index f9da783..1ddd0ae 100644 +--- a/src/libs/libxalarm/register_xalarm.c ++++ b/src/libs/libxalarm/register_xalarm.c +@@ -604,13 +604,14 @@ static bool is_valid_task_name(const char *task_name) + */ + int report_result(const char *task_name, enum RESULT_LEVEL result_level, const char *report_data) + { ++ int ret = RETURE_CODE_FAIL; + if (result_level < 0 || result_level >= RESULT_LEVEL_NUM) { +- fprintf(stderr, "result_level (%u) is invalid, it must be in [0-5]\n", result_level); +- return RETURE_CODE_FAIL; ++ fprintf(stderr, "result_level (%d) is invalid, it must be in [0-5]\n", result_level); ++ return ret; + } + + if (!is_valid_task_name(task_name)) { +- return RETURE_CODE_FAIL; ++ return ret; + } + + json_object *send_data = json_object_new_object(); +@@ -624,35 +625,36 @@ int report_result(const char *task_name, enum RESULT_LEVEL result_level, const c + const char *result_json_string = json_object_to_json_string(send_data); + if (result_json_string == NULL) { + fprintf(stderr, "%s: json_object_to_json_string return NULL", __func__); +- json_object_put(send_data); +- return RETURE_CODE_FAIL; ++ goto free_json; + } + + int send_data_len = strlen(result_json_string); + if (send_data_len > RESULT_INFO_MAX_LEN) { +- fprintf(stderr, "%s: failed to send result message (%s) to sysSentry! send data is too long (%zu) > (%d)\n", ++ fprintf(stderr, "%s: failed to send result message (%s) to sysSentry! send data is too long (%d) > (%d)\n", + __func__, result_json_string, send_data_len, RESULT_INFO_MAX_LEN); +- json_object_put(send_data); +- return RETURE_CODE_FAIL; ++ goto free_json; + } + +- char message[RESULT_INFO_HEAD_LEN + RESULT_INFO_MAX_LEN]; +- if (memset(message, 0, RESULT_INFO_HEAD_LEN + RESULT_INFO_MAX_LEN) == NULL) { +- fprintf(stderr, "%s: memset message failed", __func__); +- json_object_put(send_data); +- return RETURE_CODE_FAIL; ++ char *message = (char *)calloc(RESULT_INFO_HEAD_LEN + RESULT_INFO_MAX_LEN, sizeof(char)); ++ if (!message) { ++ fprintf(stderr, "Failed to allocate memory!"); ++ goto free_json; + } + + sprintf(message, "%s%04d%s", RESULT_INFO_HEAD_MAGIC, send_data_len, result_json_string); + + if (send_data_to_socket(RESULT_REPORT_SOCKET, message)) { + fprintf(stderr, "%s: failed to send result message (%s) to sysSentry!\n", __func__, message); +- json_object_put(send_data); +- return RETURE_CODE_FAIL; ++ goto free_msg; + } + ++ ret = RETURE_CODE_SUCCESS; ++free_msg: ++ free(message); ++ message = NULL; ++free_json: + json_object_put(send_data); +- return RETURE_CODE_SUCCESS; ++ return ret; + } + + int xalarm_register_event(struct alarm_register **register_info, struct alarm_subscription_info id_filter) +diff --git a/src/sentryPlugins/sentry_msg_monitor/sentry_msg_monitor.c b/src/sentryPlugins/sentry_msg_monitor/sentry_msg_monitor.c +index a307a96..e62c936 100644 +--- a/src/sentryPlugins/sentry_msg_monitor/sentry_msg_monitor.c ++++ b/src/sentryPlugins/sentry_msg_monitor/sentry_msg_monitor.c +@@ -94,7 +94,7 @@ static int smh_dev_get_fd(void) + static int convert_smh_msg_to_str(struct sentry_msg_helper_msg* smh_msg, char* str) + { + int res; +- char nid_str[MSG_STR_MAX_LEN]; ++ char *nid_str = NULL; + size_t offset = 0; + switch (smh_msg->type) { + case SMH_MESSAGE_POWER_OFF: +@@ -105,11 +105,18 @@ static int convert_smh_msg_to_str(struct sentry_msg_helper_msg* smh_msg, char* s + } + break; + case SMH_MESSAGE_OOM: ++ nid_str = (char *) calloc (MSG_STR_MAX_LEN, sizeof(char)); ++ if (!nid_str) { ++ logging_error("Failed to allocate memory!"); ++ return -1; ++ } + for (int i = 0; i < MAX_NUMA_NODES; i++) { + res = snprintf(nid_str + offset, MSG_STR_MAX_LEN - offset, "%d%s", + smh_msg->oom_info.nid[i], (i < MAX_NUMA_NODES - 1) ? "," : ""); + if ((size_t)res >= MSG_STR_MAX_LEN) { + logging_warn("msg str size exceeds the max value\n"); ++ free(nid_str); ++ nid_str = NULL; + return -1; + } + offset += res; +@@ -123,6 +130,8 @@ static int convert_smh_msg_to_str(struct sentry_msg_helper_msg* smh_msg, char* s + smh_msg->oom_info.timeout, + smh_msg->oom_info.reason + ); ++ free(nid_str); ++ nid_str = NULL; + if ((size_t)res >= MSG_STR_MAX_LEN) { + logging_warn("msg str size exceeds the max value\n"); + return -1; +@@ -183,7 +192,12 @@ static void* sender_thread(void* arg) { + pthread_cleanup_push(sender_cleanup, &fd); + + pthread_t partner_t; +- char str[MSG_STR_MAX_LEN]; ++ char *str = (char *) calloc (MSG_STR_MAX_LEN, sizeof(char)); ++ if (!str) { ++ logging_error("Failed to allocate memory!"); ++ close(fd); ++ goto close_recv; ++ } + + while (1) { + struct sentry_msg_helper_msg smh_msg; +@@ -236,6 +250,8 @@ static void* sender_thread(void* arg) { + + sender_err: + close(fd); ++ free(str); ++ str = NULL; + close_recv: + partner_t = *(pthread_t*)arg; + if (partner_t) +-- +2.27.0 + diff --git a/fix-cpu_alarm_fd-and-bmc_fd.patch b/fix-cpu_alarm_fd-and-bmc_fd.patch new file mode 100644 index 0000000000000000000000000000000000000000..96b37c175e70070a9690ebfed4f2fd4068d28647 --- /dev/null +++ b/fix-cpu_alarm_fd-and-bmc_fd.patch @@ -0,0 +1,47 @@ +From 46c6023ed11bd6adfe1627a6901057c4b90060fd Mon Sep 17 00:00:00 2001 +From: shixuantong +Date: Tue, 25 Feb 2025 15:20:46 +0800 +Subject: [PATCH] fix cpu_alarm_fd and bmc_fd + +--- + src/services/syssentry/syssentry.py | 24 +++++++++++++----------- + 1 file changed, 13 insertions(+), 11 deletions(-) + +diff --git a/src/services/syssentry/syssentry.py b/src/services/syssentry/syssentry.py +index 625da9a..def3ed7 100644 +--- a/src/services/syssentry/syssentry.py ++++ b/src/services/syssentry/syssentry.py +@@ -477,17 +477,19 @@ def main_loop(): + return + fd_list.append(heartbeat_fd) + +- cpu_alarm_fd = cpu_alarm_fd_create() +- if not cpu_alarm_fd: +- close_all_fd() +- return +- fd_list.append(cpu_alarm_fd) +- +- bmc_fd = bmc_fd_create() +- if not bmc_fd: +- close_all_fd() +- return +- fd_list.append(bmc_fd) ++ if CPU_EXIST: ++ cpu_alarm_fd = cpu_alarm_fd_create() ++ if not cpu_alarm_fd: ++ close_all_fd() ++ return ++ fd_list.append(cpu_alarm_fd) ++ ++ if BMC_EXIST: ++ bmc_fd = bmc_fd_create() ++ if not bmc_fd: ++ close_all_fd() ++ return ++ fd_list.append(bmc_fd) + + epoll_fd = select.epoll() + for fd in fd_list: +-- +2.27.0 + diff --git a/fix-cpu_sentry-result-when-found_fault_cores_number-.patch b/fix-cpu_sentry-result-when-found_fault_cores_number-.patch new file mode 100644 index 0000000000000000000000000000000000000000..d2faa09e92f7e65812cc97e70d92cef5b7e841ff --- /dev/null +++ b/fix-cpu_sentry-result-when-found_fault_cores_number-.patch @@ -0,0 +1,51 @@ +From 60366c62a26fbdff116f0b24a7dd6e61637ebfb9 Mon Sep 17 00:00:00 2001 +From: shixuantong +Date: Sat, 17 May 2025 15:02:39 +0800 +Subject: [PATCH] fix cpu_sentry result when found_fault_cores_number != + isolated_cores_number + +--- + selftest/test/test_cpu_sentry.py | 2 ++ + src/sentryPlugins/cpu_sentry/cpu_sentry.py | 6 ++++++ + 2 files changed, 8 insertions(+) + +diff --git a/selftest/test/test_cpu_sentry.py b/selftest/test/test_cpu_sentry.py +index 47e366b..c9af184 100644 +--- a/selftest/test/test_cpu_sentry.py ++++ b/selftest/test/test_cpu_sentry.py +@@ -20,6 +20,7 @@ class TestCaseCpuSentry: + ("1-", []), + ("-1", []), + ("", []), ++ (" ", []), + ("1-3,5-8", [1,2,3,5,6,7,8]), + ("1-3,8", [1,2,3,8]), + ("11", [11]), +@@ -53,6 +54,7 @@ class TestCaseCpuSentry: + ("0, 2-4", False), + ("1-3-6", False), + ("", False), ++ (" ", False), + ("xxx", False), + ("1-3,,", False), + ("1-3,,6", False), +diff --git a/src/sentryPlugins/cpu_sentry/cpu_sentry.py b/src/sentryPlugins/cpu_sentry/cpu_sentry.py +index 0c66fd2..e7a34ad 100644 +--- a/src/sentryPlugins/cpu_sentry/cpu_sentry.py ++++ b/src/sentryPlugins/cpu_sentry/cpu_sentry.py +@@ -142,6 +142,12 @@ class CpuSentry: + self.send_result["details"]["code"] = 1002 + self.send_result["result"] = ResultLevel.MINOR_ALM + self.send_result["details"]["msg"] = "Some CPUs are faulty. The faulty cores are isolated successfully." ++ else: ++ found_fault_cores_set = set(found_fault_cores_list) ++ isolated_cpu_set = set(CpuSentry.cpu_format_convert_to_list(self.send_result["details"]["isolated_cpu_list"])) ++ self.send_result["details"]["code"] = 1002 ++ self.send_result["result"] = ResultLevel.MINOR_ALM ++ self.send_result["details"]["msg"] = "Some cores are isolated successfully and some cores ({}) fail to be isolated.".format(list(found_fault_cores_set - isolated_cpu_set)) + + def cpu_report_result(self): + """report result to sysSentry""" +-- +2.27.0 + diff --git a/fix-env-for-subprocess.Popen.patch b/fix-env-for-subprocess.Popen.patch new file mode 100644 index 0000000000000000000000000000000000000000..d44457ea091677b2afcb52fdb803caaff609cbdb --- /dev/null +++ b/fix-env-for-subprocess.Popen.patch @@ -0,0 +1,25 @@ +From 8d6ca181b85ee32837e8891a1003d24826902f08 Mon Sep 17 00:00:00 2001 +From: shixuantong +Date: Sat, 29 Mar 2025 10:58:17 +0800 +Subject: [PATCH] fix env for subprocess.Popen + +--- + src/services/syssentry/global_values.py | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/services/syssentry/global_values.py b/src/services/syssentry/global_values.py +index 931b8ab..7cb99e0 100644 +--- a/src/services/syssentry/global_values.py ++++ b/src/services/syssentry/global_values.py +@@ -76,7 +76,7 @@ class InspectTask: + # ccnfig env_file + self.env_file = "" + # env conf to popen arg +- self.environ_conf = {} ++ self.environ_conf = None + # start mode + self.conflict = "up" + # alarm id +-- +2.27.0 + diff --git a/fix-period-task-some-bugs.patch b/fix-period-task-some-bugs.patch new file mode 100644 index 0000000000000000000000000000000000000000..a0173b98917c84e4574d7d23f41344933e0aff2e --- /dev/null +++ b/fix-period-task-some-bugs.patch @@ -0,0 +1,54 @@ +From b0af4890cd131f33ab85708c75742f0a9680705c Mon Sep 17 00:00:00 2001 +From: shixuantong +Date: Sat, 22 Mar 2025 10:38:30 +0800 +Subject: [PATCH] fix period task some bugs + +--- + src/services/syssentry/cron_process.py | 6 ++---- + 1 file changed, 2 insertions(+), 4 deletions(-) + +diff --git a/src/services/syssentry/cron_process.py b/src/services/syssentry/cron_process.py +index 204d4f3..fab350e 100644 +--- a/src/services/syssentry/cron_process.py ++++ b/src/services/syssentry/cron_process.py +@@ -59,7 +59,6 @@ class PeriodTask(InspectTask): + self.result_info["details"] = {} + if not self.period_enabled: + self.period_enabled = True +- self.upgrade_period_timestamp() + + if self.conflict != 'up': + ret = self.check_conflict() +@@ -87,6 +86,7 @@ class PeriodTask(InspectTask): + self.runtime_status = FAILED_STATUS + return False, "period task start popen failed, invalid command" + finally: ++ self.upgrade_period_timestamp() + if isinstance(logfile, io.TextIOWrapper) and not logfile.closed: + logfile.close() + +@@ -127,7 +127,6 @@ class PeriodTask(InspectTask): + res, _ = self.start() + if res: + set_runtime_status(self.name, RUNNING_STATUS) +- self.upgrade_period_timestamp() + + + def period_tasks_handle(): +@@ -142,7 +141,7 @@ def period_tasks_handle(): + logging.debug("period not enabled") + continue + +- if not task.onstart: ++ if not task.onstart and task.last_exec_timestamp == 0: + logging.debug("period onstart not enabled, task: %s", task.name) + task.runtime_status = EXITED_STATUS + continue +@@ -153,4 +152,3 @@ def period_tasks_handle(): + res, _ = task.start() + if res: + set_runtime_status(task.name, RUNNING_STATUS) +- task.upgrade_period_timestamp() +-- +2.27.0 + diff --git a/sysSentry.spec b/sysSentry.spec index 20d54c2b344dd2eeb45a5e18fb37e0ff547b711e..dda61ff8548c84285ea5db959dbfe784cd789ef5 100644 --- a/sysSentry.spec +++ b/sysSentry.spec @@ -4,7 +4,7 @@ Summary: System Inspection Framework Name: sysSentry Version: 1.0.3 -Release: 12 +Release: 13 License: Mulan PSL v2 Group: System Environment/Daemons Source0: https://gitee.com/openeuler/sysSentry/releases/download/v%{version}/%{name}-%{version}.tar.gz @@ -21,6 +21,11 @@ Patch9: ai-block-io-exit-when-stage-is-not-supported.patch Patch10: add-log-utils-for-c.patch Patch11: add-sentry-msg-monitor.patch Patch12: add-oom-event-report.patch +Patch13: fix-cpu_alarm_fd-and-bmc_fd.patch +Patch14: fix-period-task-some-bugs.patch +Patch15: fix-env-for-subprocess.Popen.patch +Patch16: Use-malloc-to-allocate-memory-as-much-as-possible.patch +Patch17: fix-cpu_sentry-result-when-found_fault_cores_number-.patch BuildRequires: cmake gcc-c++ BuildRequires: python3 python3-setuptools @@ -237,6 +242,16 @@ rm -rf /var/run/sysSentry | : %attr(0600,root,root) %{_sysconfdir}/sysSentry/tasks/sentry_msg_monitor.mod %changelog +* Thu Sep 18 2025 shixuantong - 1.0.3-13 +- Type:bugfix +- CVE:NA +- SUG:NA +- DESC:fix period task some bugs + fix env for subprocess.Popen + Use malloc to allocate memory as much as possible + fix cpu_sentry result when found_fault_cores_number != isolated_cores_number + fix cpu_alarm_fd and bmc_fd + * Fri Mar 14 2025 luckky - 1.0.3-12 - Type:feature - CVE:NA