From 411e0fe141efdf02d73aa15c2576214af1be787e Mon Sep 17 00:00:00 2001
From: zhuofeng <1107893276@qq.com>
Date: Wed, 12 Mar 2025 02:27:12 +0000
Subject: [PATCH] fix the sentryCollector service can't be stopped for a long
 time

Signed-off-by: zhuofeng <1107893276@qq.com>
---
 src/python/sentryCollector/collect_io.py | 13 +++++++++++--
 src/python/syssentry/global_values.py    |  2 +-
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/python/sentryCollector/collect_io.py b/src/python/sentryCollector/collect_io.py
index 4cf6534..622e0b4 100644
--- a/src/python/sentryCollector/collect_io.py
+++ b/src/python/sentryCollector/collect_io.py
@@ -322,6 +322,8 @@ class CollectIo():
                         if curr_io_dump > 0:
                             logging.info(f"ebpf io_dump info : {disk_name}, {stage}, {io_type}, {curr_io_dump}")
                         IO_GLOBAL_DATA[disk_name][stage][io_type].insert(0, [curr_lat, curr_io_dump, curr_io_length, curr_iops])
+                        if curr_lat > 0:
+                            logging.info(f"ebpf info : {disk_name}, {stage}, {io_type}, {curr_lat}, {curr_iops}")
 
             elapsed_time = time.time() - start_time
             sleep_time = self.period_time - elapsed_time
@@ -405,10 +407,17 @@ class CollectIo():
         self
     ) -> None:
         global EBPF_PROCESS
-        if EBPF_PROCESS:
+        if not EBPF_PROCESS:
+            logging.debug("No eBPF process to stop")
+            return
+        try:
             EBPF_PROCESS.terminate()
+            EBPF_PROCESS.wait(timeout=3)
+        except subprocess.TimeoutExpired:
+            logging.debug("eBPF process did not exit within timeout. Forcing kill.")
+            EBPF_PROCESS.kill()
             EBPF_PROCESS.wait()
-            logging.info("ebpf collector thread exit")
+        logging.info("ebpf collector thread exit")
 
     def main_loop(self):
         global IO_GLOBAL_DATA
diff --git a/src/python/syssentry/global_values.py b/src/python/syssentry/global_values.py
index b123b2d..9c7800b 100644
--- a/src/python/syssentry/global_values.py
+++ b/src/python/syssentry/global_values.py
@@ -114,7 +114,7 @@ class InspectTask:
             try:
                 child = subprocess.Popen(cmd_list, stdout=logfile, stderr=subprocess.STDOUT, close_fds=True)
             except OSError:
-                logging.error("task %s start Popen error, invalid cmd")
+                logging.error("task %s start Popen error, invalid cmd", cmd_list)
                 self.result_info["result"] = ResultLevel.FAIL.name
                 self.result_info["error_msg"] = RESULT_LEVEL_ERR_MSG_DICT.get(ResultLevel.FAIL.name)
                 self.runtime_status = "FAILED"
-- 
2.43.0

