From 62f2558c64cc18573ed029b8236a02a367549194 Mon Sep 17 00:00:00 2001 From: "lijindong (C)" <2220386943@qq.com> Date: Thu, 21 Aug 2025 19:23:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=87=87=E6=A0=B7=E8=BF=9B?= =?UTF-8?q?=E7=A8=8B=E5=AD=98=E5=9C=A8=E5=A4=9A=E7=BA=BF=E7=A8=8B=E5=9C=BA?= =?UTF-8?q?=E6=99=AF=E6=97=B6pmuopen=E8=80=97=E6=97=B6=E8=BE=83=E4=B9=85?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- util/process_map.cpp | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/util/process_map.cpp b/util/process_map.cpp index 9875e01..538617c 100644 --- a/util/process_map.cpp +++ b/util/process_map.cpp @@ -166,9 +166,9 @@ void StoreThreadId(int** childTidList, int* count, const char* entryName) } } -bool GetChildTidRecursive(const char *dirPath, int **childTidList, int *count) +bool GetChildTidRecursive(const std::string& dirPath, int **childTidList, int *count) { - DIR *dir = opendir(dirPath); + DIR *dir = opendir(dirPath.c_str()); if (!dir) { return false; } @@ -186,14 +186,6 @@ bool GetChildTidRecursive(const char *dirPath, int **childTidList, int *count) // Store the thread ID in the array StoreThreadId(childTidList, count, entry->d_name); } - - char path[PATH_LEN]; - if (snprintf(path, sizeof(path), "%s/%s", dirPath, entry->d_name) < 0) { - continue; - } - - // Continue recursively - GetChildTidRecursive(path, childTidList, count); } } @@ -210,10 +202,7 @@ int *GetChildTid(int pid, int *numChild) *numChild = 1; return childTidList; } - char dirPath[PATH_LEN]; - if (snprintf(dirPath, sizeof(dirPath), "/proc/%d/task", pid) < 0) { - return nullptr; - } + std::string dirPath = "/proc/" + std::to_string(pid) + "/task"; *numChild = 0; if (!GetChildTidRecursive(dirPath, &childTidList, numChild)) { if (childTidList) { @@ -223,5 +212,4 @@ int *GetChildTid(int pid, int *numChild) *numChild = 0; } return childTidList; -} - +} \ No newline at end of file -- Gitee