diff options
author | CoprDistGit <infra@openeuler.org> | 2024-11-21 08:03:09 +0000 |
---|---|---|
committer | CoprDistGit <infra@openeuler.org> | 2024-11-21 08:03:09 +0000 |
commit | 2d17024a365126cd94df28519c4fecd24049bc08 (patch) | |
tree | 295ad3fc676c2a6a01619a5d68e6e59af798d16b | |
parent | e36a8eabe0d4807984abf28546e5aa6b85ca7dc0 (diff) |
automatic import of sysmonitor-kmod
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | add-install-section-in-src-CMakeList.txt-and-module-Makefile.patch | 103 | ||||
-rw-r--r-- | bugfix-fix-fd-path-failed-to-open.patch | 48 | ||||
-rw-r--r-- | bugfix-fix-signal-monitor-err.patch | 207 | ||||
-rw-r--r-- | sources | 1 | ||||
-rw-r--r-- | support-monitor-process-function-by-kprobe.patch | 181 | ||||
-rw-r--r-- | sysmonitor-kmod.spec | 217 | ||||
-rw-r--r-- | update-support-loongarch-fix-compilation-errors.patch | 25 |
8 files changed, 783 insertions, 0 deletions
@@ -0,0 +1 @@ +/sysmonitor-1.3.2.tar.bz2 diff --git a/add-install-section-in-src-CMakeList.txt-and-module-Makefile.patch b/add-install-section-in-src-CMakeList.txt-and-module-Makefile.patch new file mode 100644 index 0000000..7d7f577 --- /dev/null +++ b/add-install-section-in-src-CMakeList.txt-and-module-Makefile.patch @@ -0,0 +1,103 @@ +From 5f14b328ea78ea7b375c775d894dd987ce707fdb Mon Sep 17 00:00:00 2001 +From: wangxiaomeng <wangxiaomeng@kylinos.cn> +Date: Thu, 23 May 2024 14:57:12 +0800 +Subject: [PATCH] add install section in src/CMakeList.txt and module/Makefile + +--- + module/Makefile | 30 ++++++++++++++++++++++++------ + src/CMakeLists.txt | 27 +++++++++++++++++++++++++++ + 2 files changed, 51 insertions(+), 6 deletions(-) + +diff --git a/module/Makefile b/module/Makefile +index 8030152..0ca0f86 100644 +--- a/module/Makefile ++++ b/module/Makefile +@@ -3,19 +3,37 @@ + # Author: xuchunmei + # Create: 2018-12-15 + ++KERNELVER?=$(shell uname -r) ++ + obj-m += sysmonitor.o + sysmonitor-objs := sysmonitor_main.o signo_catch.o fdstat.o monitor_netdev.o +-KERNELDIR ?= /lib/modules/$(shell uname -r)/build ++KERNELDIR ?= /lib/modules/$(KERNELVER)/build + PWD := $(shell pwd) + EXTRA_CFLAGS += -Wall -Werror + +-modules: ++default: + $(MAKE) -C $(KERNELDIR) M=$(PWD) modules + +-modules_install: +- $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install +- + clean: + $(MAKE) -C $(KERNELDIR) SUBDIRS=$(PWD) clean ++ rm -f *.ko *.o *.mod.o *.mod.c *.symvers *.order .sysmonitor* .mo* .Module* .signo* sysmonitor.mod .fdstat.* ++ ++install: ++ install -d -m 750 /lib/modules/sysmonitor ++ install -m 640 sysmonitor.ko /lib/modules/sysmonitor ++ lsmod | grep -qw sysmonitor && modprobe -r sysmonitor || true ++ if [ -e "/lib/modules/sysmonitor/sysmonitor.ko" ];then \ ++ /sbin/depmod -aeF /boot/System.map-$(KERNELVER) $(KERNELVER) > /dev/null;\ ++ insmod /lib/modules/sysmonitor/sysmonitor.ko 2>/dev/null 1>/dev/null;\ ++ if [ $$? -ne 0 ];then { echo "sysmonitor.ko modprobe is failed.";exit 0;} fi;\ ++ else\ ++ echo "The /lib/modules/sysmonitor/sysmonitor.ko file does not exist in the sysmonitor rpm package";\ ++ exit 0; \ ++ fi + +-.PHONY: modules modules_install clean ++uninstall: ++ if [ $(id -u) -ne 0 ]; then { echo "root permission is required to uninstall sysmonitor";exit 0;} fi ++ ps h -C sysmonitor -o pid && killall sysmonitor || true ++ lsmod | grep -qw sysmonitor && modprobe -r sysmonitor || true ++ rm -rf /lib/modules/sysmonitor ++ /sbin/depmod -aeF /boot/System.map-$(KERNELVER) $(KERNELVER) > /dev/null +diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt +index e5af612..4943c8f 100644 +--- a/src/CMakeLists.txt ++++ b/src/CMakeLists.txt +@@ -6,6 +6,12 @@ + project(sysmonitor) + + set(CMAKE_C_FLAGS "-Wall -Werror -D_FORTIFY_SOURCE=2 -O2 -fPIE -fstack-protector-strong -g") ++set(CMAKE_INSTALL_SYSCONFDIR "/etc") ++set(CMAKE_INSTALL_LIBEXECDIR "/usr/libexec") ++set(CMAKE_INSTALL_SYSLOGDIR "/etc/rsyslog.d") ++set(CMAKE_INSTALL_SBINDIR "/usr/sbin") ++set(CMAKE_INSTALL_BINDIR "/usr/bin") ++set(SYSTEMD_SERVICEDIR "/usr/lib/systemd/system/") + + if (VERSION) + add_compile_options(-D ${VERSION}) +@@ -18,3 +24,24 @@ endif(CUSTOM) + add_executable(sysmonitor common.c custom.c disk.c fsmonitor.c filemonitor.c process.c sys_resources.c sys_event.c sysmonitor.c zombie.c monitor_thread.c) + set_target_properties(sysmonitor PROPERTIES LINK_FLAGS "-Wl,-z,relro -Wl,-z,noexecstack -Wl,-z,now -Wtrampolines -pie") + target_link_libraries(sysmonitor boundscheck pthread) ++install(TARGETS sysmonitor DESTINATION ${CMAKE_INSTALL_BINDIR}) ++install(DIRECTORY ../conf/ DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/sysmonitor PATTERN "rsyslog.d " EXCLUDE PATTERN "clock_transition" EXCLUDE PATTERN "io_monitor" EXCLUDE PATTERN "logind_monitor" EXCLUDE PATTERN "sysmonitor" EXCLUDE PATTERN "io_monitor" EXCLUDE) ++install(FILES ../conf/rsyslog.d/sysmonitor.conf DESTINATION ${CMAKE_INSTALL_SYSLOGDIR}) ++install(FILES ../conf/logrotate.d/sysmonitor-logrotate DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/sysmonitor) ++install(FILES ../conf/clock_transition DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/sysmonitor.d) ++install(FILES ../conf/io_monitor DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/sysmonitor.d) ++install(FILES ../conf/logind_monitor DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/sysmonitor.d) ++install(FILES ../conf/sysmonitor DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/sysconfig) ++ ++install(DIRECTORY ../script/ DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/sysmonitor PATTERN "iomonitor_daemon" EXCLUDE) ++install(PROGRAMS ../script/iomonitor_daemon DESTINATION ${CMAKE_INSTALL_SBINDIR}) ++install(FILES ../conf/io_monitor DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/sysmonitor.d) ++install(FILES ../service/sysmonitor.service DESTINATION ${SYSTEMD_SERVICEDIR}) ++ ++add_custom_target(uninstall ++ COMMAND rm -rf /etc/sysmonitor /usr/libexec/sysmonitor /etc/rsyslog.d/sysmonitor.conf /etc/sysmonitor.d/ ++ COMMAND rm -rf /usr/lib/systemd/system/sysmonitor.service ++ COMMAND rm -rf /usr/sbin/iomonitor_daemon /usr/bin/sysmonitor ++ COMMENT "Uninstall sysmonitor" ++ VERBATIM ++) +-- +2.43.0 + diff --git a/bugfix-fix-fd-path-failed-to-open.patch b/bugfix-fix-fd-path-failed-to-open.patch new file mode 100644 index 0000000..bab67b0 --- /dev/null +++ b/bugfix-fix-fd-path-failed-to-open.patch @@ -0,0 +1,48 @@ +From 9241d98bc5803d18b1e17bd3ba1b84e97207fab4 Mon Sep 17 00:00:00 2001 +From: tenglei <tenglei@kylinos.cn> +Date: Thu, 11 Apr 2024 17:55:13 +0800 +Subject: [PATCH] bugfix fix fd path failed to open + +--- + src/sys_event.c | 22 ++++++++++++++++------ + 1 file changed, 16 insertions(+), 6 deletions(-) + +diff --git a/src/sys_event.c b/src/sys_event.c +index 61701ec..dbdb9d0 100644 +--- a/src/sys_event.c ++++ b/src/sys_event.c +@@ -544,15 +544,25 @@ static int chang_kernel_interface_value(void) + return -1; + } + +- ret = set_value_to_file(buf, PROC_FDTHRESHOLD); +- if (ret == -1) { +- log_printf(LOG_ERR, "chang_kernel_interface_value: set_value_to_file failed"); ++ if (access(PROC_FDTHRESHOLD, F_OK) == 0) { ++ ret = set_value_to_file(buf, PROC_FDTHRESHOLD); ++ if (ret == -1) { ++ log_printf(LOG_ERR, "chang_kernel_interface_value: set_value_to_file failed"); ++ return -1; ++ } ++ } else { ++ log_printf(LOG_ERR, "fdthreshold function is not supported in the current system environment"); + return -1; + } + +- ret = set_value_to_file("1", RROC_FDENABLE); +- if (ret == -1) { +- log_printf(LOG_ERR, "chang_kernel_interface_value: set_value_to_file failed"); ++ if (access(RROC_FDENABLE, F_OK) == 0) { ++ ret = set_value_to_file("1", RROC_FDENABLE); ++ if (ret == -1) { ++ log_printf(LOG_ERR, "chang_kernel_interface_value: set_value_to_file failed"); ++ return -1; ++ } ++ } else { ++ log_printf(LOG_ERR, "fdenable function is not supported in the current system environment"); + return -1; + } + +-- +2.27.0 + diff --git a/bugfix-fix-signal-monitor-err.patch b/bugfix-fix-signal-monitor-err.patch new file mode 100644 index 0000000..a138377 --- /dev/null +++ b/bugfix-fix-signal-monitor-err.patch @@ -0,0 +1,207 @@ +From 619aaa241ec852ea44aa3edbd59aa9c08b8adc9f Mon Sep 17 00:00:00 2001 +From: xietangxin <xietangxin@huawei.com> +Date: Wed, 22 Nov 2023 14:26:13 +0800 +Subject: [PATCH] bugfix: fix signal monitor err + +--- + module/signo_catch.c | 68 ++++++++++++++++----------- + module/signo_catch.h | 6 +++ + src/sys_event.c | 1 + + 3 files changed, 48 insertions(+), 27 deletions(-) + +diff --git a/module/signo_catch.c b/module/signo_catch.c +index 5273f29..c038e16 100644 +--- a/module/signo_catch.c ++++ b/module/signo_catch.c +@@ -12,6 +12,7 @@ + #include <linux/netlink.h> + #include <linux/notifier.h> + #include <linux/proc_fs.h> ++#include <linux/kprobes.h> + + #include "sysmonitor_main.h" + +@@ -28,6 +29,10 @@ static ulong g_qemu_buf_seq; /* index for reader */ + static qemu_signo_msg g_qemu_buf[SIG_BUFSIZE]; + struct proc_dir_entry *g_proc_qemu; + ++static struct kprobe kp = { ++ .symbol_name = "do_send_sig_info" ++}; ++ + static ssize_t qemu_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) + { + int error, index; +@@ -91,7 +96,6 @@ static const struct proc_ops g_proc_qemu_operations = { + }; + #endif + +-#ifdef CONFIG_EULEROS_SYSMONITOR_SIGNAL + /* Here introduce euler_get_mm_exe_file and euler_get_task_exe_file + * to solve the build and insmod error. + */ +@@ -132,16 +136,16 @@ static struct file *euler_get_task_exe_file(struct task_struct *task) + static int save_exe_info(char *exe, int exe_size, struct task_struct *task) + { + struct file *exe_file = NULL; +- int ret; ++ void *ret; + + exe_file = euler_get_task_exe_file(task); + if (exe_file != NULL) { + ret = memcpy(exe, + exe_file->f_path.dentry->d_name.name, + exe_file->f_path.dentry->d_name.len); +- if (ret != 0) { ++ if (ret == NULL) { + fput(exe_file); +- return ret; ++ return -1; + } + fput(exe_file); + } +@@ -200,8 +204,6 @@ static int save_msg_info(ce_signo_msg *msg, const send_sig_info_data_t *notifier + + static int save_qemu_msg_info(qemu_signo_msg *qemu_msg, const send_sig_info_data_t *notifier_call_data) + { +- int ret; +- + (void)memset(qemu_msg, 0, sizeof(qemu_signo_msg)); + qemu_msg->send_pid = current->pid; + (void)memcpy(qemu_msg->send_comm, current->comm, TASK_COMM_LEN); +@@ -213,18 +215,17 @@ static int save_qemu_msg_info(qemu_signo_msg *qemu_msg, const send_sig_info_data + return 0; + } + +-static int do_store_sig_info(struct notifier_block *self, unsigned long val, void *data) ++static int do_store_sig_info(send_sig_info_data_t *data) + { +- send_sig_info_data_t *notifier_call_data = (send_sig_info_data_t *)data; + ce_signo_msg msg; + ulong index; + qemu_signo_msg *qemu_msg = NULL; + unsigned long sigcatchmask = get_sigcatchmask(); + int ret; + +- if ((notifier_call_data->sig <= SIGNAL_COUNT) && +- (sigcatchmask & (1ul << (unsigned int)(notifier_call_data->sig - 1)))) { +- ret = save_msg_info(&msg, notifier_call_data); ++ if ((data->sig <= SIGNAL_COUNT) && ++ (sigcatchmask & (1ul << (unsigned int)(data->sig - 1)))) { ++ ret = save_msg_info(&msg, data); + if (ret != 0) { + goto out; + } +@@ -233,12 +234,12 @@ static int do_store_sig_info(struct notifier_block *self, unsigned long val, voi + } + + #ifdef QEMU_SIG +- if ((notifier_call_data->sig == SIGKILL) && +- !strcmp(notifier_call_data->p->comm, "qemu-kvm")) { ++ if ((data->sig == SIGKILL) && ++ !strcmp(data->p->comm, "qemu-kvm")) { + index = g_qemu_buf_seq & SIG_BUFMASK; + qemu_msg = g_qemu_buf + index; + +- ret = save_qemu_msg_info(qemu_msg, notifier_call_data); ++ ret = save_qemu_msg_info(qemu_msg, data); + if (ret) { + goto out; + } +@@ -251,15 +252,30 @@ static int do_store_sig_info(struct notifier_block *self, unsigned long val, voi + } + #endif + out: +- return NOTIFY_DONE; ++ return 0; + } + +-static struct notifier_block g_signo_catch_nb = { +- .notifier_call = do_store_sig_info, +- .priority = NOTIFY_CALL_PRIORITY, +-}; ++static int pre_handler(struct kprobe *p, struct pt_regs *regs) ++{ ++#ifdef CONFIG_ARM64 ++ send_sig_info_data_t data; ++ data.sig = regs->regs[0]; ++ data.info = (struct kernel_siginfo *)((unsigned long *)regs->regs[1]); ++ data.p = (struct task_struct *)((unsigned long *)regs->regs[2]); ++ do_store_sig_info(&data); + #endif + ++#ifdef CONFIG_X86_64 ++ send_sig_info_data_t data; ++ data.sig = regs->di; ++ data.info = (struct kernel_siginfo *)((unsigned long *)regs->si); ++ data.p = (struct task_struct *)((unsigned long *)regs->dx); ++ do_store_sig_info(&data); ++#endif ++ return 0; ++} ++ ++ + void signo_catch_init(void) + { + #ifdef QEMU_SIG +@@ -268,22 +284,20 @@ void signo_catch_init(void) + printk(KERN_ERR "signo_catch: create /proc/sig_catch failed.\n"); + } + #endif +-#ifdef CONFIG_EULEROS_SYSMONITOR_SIGNAL +- (void)register_signo_catch_notifier(&g_signo_catch_nb); +-#endif +- printk(KERN_INFO "signo_catch: Planted send_sig_info_notifier_list register\n"); ++ kp.pre_handler = pre_handler; ++ register_kprobe(&kp); ++ ++ printk(KERN_INFO "signo_catch: register signal kprobe\n"); + } + + void signo_catch_exit(void) + { +-#ifdef CONFIG_EULEROS_SYSMONITOR_SIGNAL +- (void)unregister_signo_catch_notifier(&g_signo_catch_nb); +-#endif ++ unregister_kprobe(&kp); + #ifdef QEMU_SIG + if (g_proc_qemu != NULL) { + proc_remove(g_proc_qemu); + } + #endif +- printk(KERN_INFO "signo_catch: send_sig_info_notifier_list unregistered\n"); ++ printk(KERN_INFO "signo_catch: unregister signal kprobe\n"); + } + +diff --git a/module/signo_catch.h b/module/signo_catch.h +index 0c2b9f7..b2ce684 100644 +--- a/module/signo_catch.h ++++ b/module/signo_catch.h +@@ -38,6 +38,12 @@ typedef struct __signo_msg { + char recv_comm[TASK_COMM_LEN]; + } qemu_signo_msg; + ++typedef struct send_sig_info_data { ++ int sig; ++ struct kernel_siginfo *info; ++ struct task_struct *p; ++} send_sig_info_data_t; ++ + void signo_catch_init(void); + void signo_catch_exit(void); + +diff --git a/src/sys_event.c b/src/sys_event.c +index 61701ec..9674b98 100644 +--- a/src/sys_event.c ++++ b/src/sys_event.c +@@ -681,6 +681,7 @@ static int handle_signo_msg(const sysmonitor_event_msg *event_msg) + log_printf(LOG_ERR, "sig_monitor_start: snprintf_s alarm_msg failed."); + return -1; + } ++ log_printf(LOG_INFO, "%s", alarm_msg); + } + + return 0; +-- +2.20.1.windows.1 + @@ -0,0 +1 @@ +5eee8f4d54d7ceed33836ec4afa646bc sysmonitor-1.3.2.tar.bz2 diff --git a/support-monitor-process-function-by-kprobe.patch b/support-monitor-process-function-by-kprobe.patch new file mode 100644 index 0000000..10b9736 --- /dev/null +++ b/support-monitor-process-function-by-kprobe.patch @@ -0,0 +1,181 @@ +From d08bab23c4b4a49a7e81528c142ec515b48b396a Mon Sep 17 00:00:00 2001 +From: guo-zhicheng666 <1678717630@qq.com> +Date: Wed, 18 Sep 2024 20:43:24 +0800 +Subject: [PATCH] support monitor process function by kprobe + +Signed-off-by: guo-zhicheng666 <1678717630@qq.com> +--- + module/fdstat.c | 123 ++++++++++++++++++++++++++++++++++++++++-------- + module/fdstat.h | 2 - + 2 files changed, 104 insertions(+), 21 deletions(-) + +diff --git a/module/fdstat.c b/module/fdstat.c +index 5b1aa9a..c2f7d1d 100644 +--- a/module/fdstat.c ++++ b/module/fdstat.c +@@ -11,40 +11,125 @@ + #include <linux/poll.h> + #include <linux/proc_fs.h> + #include <linux/uaccess.h> ++#include <linux/fdtable.h> ++#include <linux/atomic.h> ++#include <linux/kernel.h> ++#include <linux/module.h> ++#include <linux/fs.h> ++#include <linux/seq_file.h> ++#include <linux/uaccess.h> ++#include <linux/resource.h> ++ ++#include <asm/ptrace.h> ++#include <asm/current.h> ++#include <linux/kprobes.h> + + #include "sysmonitor_main.h" + +-#ifdef CONFIG_EULEROS_SYSMONITOR_FD +-static int do_fdstat(struct notifier_block *self, unsigned long val, void *data) ++static unsigned int fdthreshold = 80; ++struct proc_dir_entry *fdthreshold_entry = NULL; ++ ++static unsigned int count_fd_num(struct fdtable *fdt) ++{ ++ unsigned int size = fdt->max_fds; ++ unsigned int fd; ++ unsigned int handle_count = 0; ++ ++ /* Find the last open fd */ ++ for (fd = 0; fd < size; fd++) { ++ if (fdt->fd[fd]) ++ handle_count++; ++ } ++ return handle_count; ++} ++ ++static int handler_pre(struct kprobe *p, struct pt_regs *regs) + { +- struct fdstat *notifier_call_data = (struct fdstat *)data; + struct fdstat msg; ++ unsigned int total_fd_num = 0; ++ struct files_struct *files = current->files; ++ struct fdtable *fdt = files_fdtable(files); ++ ++ if (fdt) { ++ total_fd_num = count_fd_num(fdt); ++ } ++ ++ if (total_fd_num == (unsigned int)rlimit(RLIMIT_NOFILE) * fdthreshold / 100) { ++ pr_err("total_fd_num : %u\n", total_fd_num); ++ (void)memset(&msg, 0, sizeof(struct fdstat)); ++ msg.pid = current->pid; ++ msg.total_fd_num = total_fd_num; ++ (void)memcpy(msg.comm, current->comm, TASK_COMM_LEN); ++ (void)save_msg(FDSTAT, &msg, sizeof(struct fdstat)); ++ } ++ ++ return 0; ++} ++ ++static int fdthreshold_show(struct seq_file *userfile, void *v) ++{ ++ seq_printf(userfile, "%u\n", fdthreshold); ++ return 0; ++} ++ ++static int fdthreshold_open(struct inode *inode, struct file *file) ++{ ++ single_open(file, fdthreshold_show, NULL); ++ ++ return 0; ++} ++ ++static ssize_t fdthreshold_write(struct file *file, const char __user *ubuf, ++ size_t cnt, loff_t *ppos) ++{ + int ret; ++ unsigned int val; ++ ++ ret = kstrtouint_from_user(ubuf, cnt, 10, &val); ++ if (ret) { ++ pr_err("[fdstat] parse fdthreshold failed\n"); ++ return ret; ++ } + +- (void)memset(&msg, 0, sizeof(struct fdstat)); +- msg.pid = notifier_call_data->pid; +- msg.total_fd_num = notifier_call_data->total_fd_num + 1; +- (void)memcpy(msg.comm, notifier_call_data->comm, TASK_COMM_LEN); +- (void)save_msg(FDSTAT, &msg, sizeof(struct fdstat)); +- return NOTIFY_DONE; ++ if (val < 1 || val > 99) { ++ pr_err("[fdstat] fdthreshold is invalid\n"); ++ return -EINVAL; ++ } ++ ++ fdthreshold = val; ++ ++ return cnt; + } + +-static struct notifier_block g_fdstat_nb = { +- .notifier_call = do_fdstat, +- .priority = NOTIFY_CALL_PRIORITY, ++static const struct proc_ops fdthreshold_operations = { ++ .proc_open = fdthreshold_open, ++ .proc_read = seq_read, ++ .proc_lseek = seq_lseek, ++ .proc_release = single_release, ++ .proc_write = fdthreshold_write, ++}; ++ ++static struct kprobe kp = { ++ .symbol_name = "do_sys_openat2", ++ .pre_handler = handler_pre, + }; +-#endif + + void fdstat_init(void) + { +-#ifdef CONFIG_EULEROS_SYSMONITOR_FD +- (void)register_fdstat_notifier(&g_fdstat_nb); +-#endif ++ if (register_kprobe(&kp) < 0) ++ pr_err("Failed to register handler for %s\n", kp.symbol_name); ++ ++ fdthreshold_entry = proc_create("fdthreshold", 0600, NULL, &fdthreshold_operations); ++ if (!fdthreshold_entry) { ++ pr_err("[fdstat]: create /proc/fdthreshold failed\n"); ++ } + } + + void fdstat_exit(void) + { +-#ifdef CONFIG_EULEROS_SYSMONITOR_FD +- (void)unregister_fdstat_notifier(&g_fdstat_nb); +-#endif ++ unregister_kprobe(&kp); ++ ++ if (fdthreshold_entry != NULL) { ++ proc_remove(fdthreshold_entry); ++ } + } +diff --git a/module/fdstat.h b/module/fdstat.h +index ae9ccc3..1a389ca 100644 +--- a/module/fdstat.h ++++ b/module/fdstat.h +@@ -10,13 +10,11 @@ + #include <linux/types.h> + #include <linux/sched.h> + +-#ifndef CONFIG_EULEROS_SYSMONITOR_FD + struct fdstat { + pid_t pid; + unsigned int total_fd_num; + char comm[TASK_COMM_LEN]; + }; +-#endif + + void fdstat_init(void); + void fdstat_exit(void); +-- +2.33.0 + diff --git a/sysmonitor-kmod.spec b/sysmonitor-kmod.spec new file mode 100644 index 0000000..814b767 --- /dev/null +++ b/sysmonitor-kmod.spec @@ -0,0 +1,217 @@ +# needssslcertforbuild +# +# spec file for package sysmonitor +# +# Copyright (c) Huawei Technologies Co., Ltd. 2014-2019. All rights reserved. +# + +%define kmod_name sysmonitor +%define version 1.3.2 +%define releaseversion 1.8 +Summary: System Monitor Daemon +Name: %{kmod_name}-kmod +Version: %{version} +Release: %{releaseversion} +License: GPLv2 and Mulan PSL v2 +Group: System Environment/Daemons +Source0: %{kmod_name}-%{version}.tar.bz2 +BuildRequires: libboundscheck +Requires: systemd +BuildRequires: module-init-tools +BuildRequires: kernel-devel +BuildRequires: dos2unix +BuildRequires: elfutils-libelf-devel +BuildRequires: systemd cmake gcc-c++ +BuildRequires: libcap-devel +BuildRequires: uname-build-checks +Requires: bash dhcp gawk kmod logrotate +Requires: net-tools which file +#for test +BuildRequires: CUnit CUnit-devel +Requires: libboundscheck +Requires: kernel >= 3.10.0-514.44.5.10 +Requires: iotop +Requires: python3 +Provides: sysmonitor +%{?systemd_requires} + +Patch1: bugfix-fix-signal-monitor-err.patch +Patch2: bugfix-fix-fd-path-failed-to-open.patch +Patch3: update-support-loongarch-fix-compilation-errors.patch +Patch4: add-install-section-in-src-CMakeList.txt-and-module-Makefile.patch +Patch5: support-monitor-process-function-by-kprobe.patch + +%description +System Monitor Daemon + +%prep +%autosetup -n %{kmod_name}-%{version} -p1 + +%build +%cmake +%cmake_build +cd module +make KDIR=/lib/modules/`uname -r`/build +strip -g sysmonitor.ko + +%install +#export BRP_PESIGN_FILES="*.ko" + +dos2unix %_builddir/%{kmod_name}-%{version}/script/iomonitor_daemon +dos2unix %_builddir/%{kmod_name}-%{version}/conf/io_monitor + +mkdir -p %{buildroot}%{_sbindir} +mkdir -p %{buildroot}/etc/sysmonitor.d/ + +install -d %{buildroot}%{_bindir} +install -d %{buildroot}%{_sysconfdir}/sysconfig +install -d -m 700 %{buildroot}%{_sysconfdir}/sysmonitor/ +install -d -m 700 %{buildroot}%{_sysconfdir}/sysmonitor/process +install -d -m 700 %{buildroot}%{_libexecdir}/sysmonitor +install -d -m 700 %{buildroot}%{_sysconfdir}/sysmonitor.d/ +install -d %{buildroot}/etc/rsyslog.d/ +install -d -m 750 %{buildroot}/lib/modules/sysmonitor +install -d -m 750 %{buildroot}%{_libexecdir}/sysmonitor/data + +install -m 600 conf/process/* %{buildroot}%{_sysconfdir}/sysmonitor/process +install -m 600 conf/signal %{buildroot}%{_sysconfdir}/sysmonitor +install -m 600 conf/network %{buildroot}%{_sysconfdir}/sysmonitor +install -m 500 src/sysmonitor %{buildroot}%{_bindir} +install -m 600 conf/sysmonitor %{buildroot}%{_sysconfdir}/sysconfig/sysmonitor +install -m 640 module/sysmonitor.ko %{buildroot}/lib/modules/sysmonitor +install -m 600 conf/disk %{buildroot}%{_sysconfdir}/sysmonitor/disk +install -m 600 conf/inode %{buildroot}%{_sysconfdir}/sysmonitor/inode +install -m 600 conf/file %{buildroot}%{_sysconfdir}/sysmonitor/file +install -m 600 conf/cpu %{buildroot}%{_sysconfdir}/sysmonitor/cpu +install -m 600 conf/memory %{buildroot}%{_sysconfdir}/sysmonitor/memory +install -m 600 conf/pscnt %{buildroot}%{_sysconfdir}/sysmonitor/pscnt +install -m 600 conf/iodelay %{buildroot}%{_sysconfdir}/sysmonitor/iodelay +install -m 600 conf/process_fd_conf %{buildroot}%{_sysconfdir}/sysmonitor/process_fd_conf +install -m 600 conf/sys_fd_conf %{buildroot}%{_sysconfdir}/sysmonitor/sys_fd_conf +install -m 600 conf/w_log_conf %{buildroot}%{_sysconfdir}/sysmonitor/w_log_conf +install -m 500 script/get_local_disk.sh %{buildroot}%{_libexecdir}/sysmonitor/ +install -m 500 script/check_sshd.sh %{buildroot}%{_libexecdir}/sysmonitor/ +install -m 500 script/check_dbus.sh %{buildroot}%{_libexecdir}/sysmonitor/ +install -m 600 conf/rsyslog.d/sysmonitor.conf %{buildroot}/etc/rsyslog.d/sysmonitor.conf +install -m 500 script/check_syslog.sh %{buildroot}%{_libexecdir}/sysmonitor/ +install -m 600 conf/logrotate.d/sysmonitor-logrotate %{buildroot}%{_libexecdir}/sysmonitor/sysmonitor-logrotate +install -m 500 script/sysmonitor_log_dump.sh %{buildroot}%{_libexecdir}/sysmonitor/ +install -m 500 script/check_cron.sh %{buildroot}%{_libexecdir}/sysmonitor/ +install -m 600 conf/clock_transition %{buildroot}%{_sysconfdir}/sysmonitor.d/clock_transition +install -m 500 script/clocktransition.py %{buildroot}%{_libexecdir}/sysmonitor/ +install -m 500 script/ko.sh %{buildroot}%{_libexecdir}/sysmonitor/ +install -m 500 script/rm_duplicat_conf.sh %{buildroot}%{_libexecdir}/sysmonitor/ +install -m 500 script/process_clock_data.sh %{buildroot}%{_libexecdir}/sysmonitor/ +install -m 500 script/iomonitor_daemon %{buildroot}%{_sbindir} +install -m 600 conf/io_monitor %{buildroot}/etc/sysmonitor.d/ +install -m 600 conf/zombie %{buildroot}%{_sysconfdir}/sysmonitor/zombie +install -m 500 script/getzombieparent.py %{buildroot}%{_libexecdir}/sysmonitor/ +install -m 500 script/clean_remain_process.sh %{buildroot}%{_libexecdir}/sysmonitor/ + +mkdir -p $RPM_BUILD_ROOT%{_unitdir}/multi-user.target.wants +mkdir -p $RPM_BUILD_ROOT/etc/systemd/ +install -m 600 conf/logind_monitor %{buildroot}%{_sysconfdir}/sysmonitor.d/ +install -m 500 script/logind_clear.sh %{buildroot}%{_libexecdir}/sysmonitor/ + +install -m 0600 service/sysmonitor.service $RPM_BUILD_ROOT%{_unitdir}/sysmonitor.service +ln -s ../sysmonitor.service $RPM_BUILD_ROOT%{_unitdir}/multi-user.target.wants/sysmonitor.service + +%post +%systemd_post sysmonitor.service + +%preun +%systemd_preun sysmonitor.service + +%postun +if [ "$1" == "0" ] +then + rmmod sysmonitor 2>/dev/null 1>/dev/null +fi +%systemd_postun_with_restart sysmonitor.service +depmod -a + +%posttrans +for line in $(ls /lib/modules/) +do + if [ -L /lib/modules/"$line"/weak-updates/sysmonitor/sysmonitor.ko ];then + rm -rf /lib/modules/"$line"/weak-updates/sysmonitor + fi +done +depmod -a $(uname -r) +systemctl daemon-reload 2>/dev/null 1>/dev/null + +%files +%defattr(-,root,root) +%dir %{_sysconfdir}/sysmonitor +%dir %{_sysconfdir}/sysmonitor/process +%dir %{_sysconfdir}/sysmonitor.d/ +%dir %{_libexecdir}/sysmonitor +%dir %attr(0550,root,root) /lib/modules/sysmonitor +%config(noreplace) %{_sysconfdir}/sysconfig/sysmonitor +%config(noreplace) %{_sysconfdir}/sysmonitor/* +%config(noreplace) %{_sysconfdir}/sysmonitor/process/* +%{_bindir}/sysmonitor + +%{_libexecdir}/sysmonitor/* +%attr(0500,root,root) %{_libexecdir}/sysmonitor/sysmonitor_log_dump.sh +%config(noreplace) %attr(0600,root,root) %{_libexecdir}/sysmonitor/sysmonitor-logrotate +%exclude %{_libexecdir}/sysmonitor/*.pyc +%exclude %{_libexecdir}/sysmonitor/*.pyo +%dir %attr(0700,root,root) %{_libexecdir}/sysmonitor/data +%attr(0400,root,root) /lib/modules/sysmonitor/sysmonitor.ko + +%config(noreplace) /etc/rsyslog.d/sysmonitor.conf +%attr(0500,root,root) %{_sbindir}/iomonitor_daemon +%attr(0600,root,root) /etc/sysmonitor.d/io_monitor + +%config(noreplace) %{_sysconfdir}/sysmonitor.d/* +%{_unitdir}/sysmonitor.service +%{_unitdir}/multi-user.target.wants/sysmonitor.service + +%changelog +* Thu Nov 21 2024 Funda Wang <fundawang@yeah.net> - 1.3.2-1.8 +- adopt to new cmake macro + +* Sun Sep 22 2024 guo-zhicheng666<1678717630@qq.com> - 1.3.2-1.7 +- Type:bugfix +- CVE:NA +- DESC:support monitor process function by kprobe + +* Thu May 23 2024 wangxiaomeng <wangxiaomeng@kylinos.cn> - 1.3.2-1.6 +- Type:bugfix +- CVE:NA +- DESC:add install section + +* Mon Jun 03 2024 yueyuankun <yueyuankun@kylinos.cn> - 1.3.2-1.5 +- Type:update +- CVE:NA +- SUG:NA +- DESC: support loongarch, fix compilation errors + +* Thu Apr 11 2024 tenglei <tenglei@kylinos.cn> - 1.3.2-1.4 +- Type:bugfix +- CVE:NA +- DESC:fix bug fd interface failed to open + +* Sun Feb 04 2024 ChenYanpan <chenyanpan@xfusion.com> - 1.3.2-1.3 +- Type:bugfix +- CVE:NA +- DESC:rename %rpmversion to %version, to fix build failure + +* Tue Nov 28 2023 xietangxin<xietangxin@huawei.com> - 1.3.2-1.2 +- Type:bugfix +- CVE:NA +- SUG:restart +- DESC: fix signal monitor err + +* Mon Jul 24 2023 zhang_chunjing<zhang_chunjing@hoperun.com> - 1.3.2-1.1 +- Type:bugfix +- CVE:NA +- SUG:restart +- DESC: add systemd to BuildRequires to fix install/uninstall errors + +* Sat May 27 2023 xietangxin<xietangxin@huawei.com> - 1.3.2-1.0 +- Type:bugfix +- CVE:NA +- SUG:restart +- DESC: init for sysmonitor diff --git a/update-support-loongarch-fix-compilation-errors.patch b/update-support-loongarch-fix-compilation-errors.patch new file mode 100644 index 0000000..2958fae --- /dev/null +++ b/update-support-loongarch-fix-compilation-errors.patch @@ -0,0 +1,25 @@ +From fb19b25f3723c6274bf0225c0cbd33180e726707 Mon Sep 17 00:00:00 2001 +From: yueyuankun <yueyuankun@kylinos.cn> +Date: Mon, 3 Jun 2024 14:54:20 +0800 +Subject: [PATCH] support loongarch, fix compilation errors + +--- + module/signo_catch.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/module/signo_catch.c b/module/signo_catch.c +index c038e16..a9270e0 100644 +--- a/module/signo_catch.c ++++ b/module/signo_catch.c +@@ -257,7 +257,7 @@ out: + + static int pre_handler(struct kprobe *p, struct pt_regs *regs) + { +-#ifdef CONFIG_ARM64 ++#if (defined(CONFIG_ARM64) || defined(CONFIG_LOONGARCH)) + send_sig_info_data_t data; + data.sig = regs->regs[0]; + data.info = (struct kernel_siginfo *)((unsigned long *)regs->regs[1]); +-- +2.43.0 + |