111 lines
3.6 KiB
Diff
111 lines
3.6 KiB
Diff
From 2eba7f18281d1a7a6a728095cd16b1ebb1b36c0a Mon Sep 17 00:00:00 2001
|
|
From: Kemeng Shi <shikemeng@huawei.com>
|
|
Date: Wed, 28 Apr 2021 19:48:33 +0800
|
|
Subject: [PATCH 12/50] add recursive in etmemd_get_task_pids to control if it
|
|
should get child pids. cslide will not get child pids.
|
|
|
|
Signed-off-by: Kemeng Shi <shikemeng@huawei.com>
|
|
---
|
|
inc/etmemd_inc/etmemd_task.h | 2 +-
|
|
src/etmemd_src/etmemd_cslide.c | 2 +-
|
|
src/etmemd_src/etmemd_pool_adapter.c | 2 +-
|
|
src/etmemd_src/etmemd_task.c | 23 +++++++++++++----------
|
|
4 files changed, 16 insertions(+), 13 deletions(-)
|
|
|
|
diff --git a/inc/etmemd_inc/etmemd_task.h b/inc/etmemd_inc/etmemd_task.h
|
|
index d6d89ea..3f32be5 100644
|
|
--- a/inc/etmemd_inc/etmemd_task.h
|
|
+++ b/inc/etmemd_inc/etmemd_task.h
|
|
@@ -51,7 +51,7 @@ struct task {
|
|
struct task *next;
|
|
};
|
|
|
|
-int etmemd_get_task_pids(struct task *tk);
|
|
+int etmemd_get_task_pids(struct task *tk, bool recursive);
|
|
|
|
void etmemd_free_task_pids(struct task *tk);
|
|
|
|
diff --git a/src/etmemd_src/etmemd_cslide.c b/src/etmemd_src/etmemd_cslide.c
|
|
index 1749383..43d8108 100644
|
|
--- a/src/etmemd_src/etmemd_cslide.c
|
|
+++ b/src/etmemd_src/etmemd_cslide.c
|
|
@@ -1899,7 +1899,7 @@ static int cslide_fill_task(GKeyFile *config, struct task *tk)
|
|
}
|
|
|
|
tk->params = params;
|
|
- if (etmemd_get_task_pids(tk) != 0) {
|
|
+ if (etmemd_get_task_pids(tk, false) != 0) {
|
|
etmemd_log(ETMEMD_LOG_ERR, "cslide fail to get task pids\n");
|
|
tk->params = NULL;
|
|
goto exit;
|
|
diff --git a/src/etmemd_src/etmemd_pool_adapter.c b/src/etmemd_src/etmemd_pool_adapter.c
|
|
index 417f864..b879dbc 100644
|
|
--- a/src/etmemd_src/etmemd_pool_adapter.c
|
|
+++ b/src/etmemd_src/etmemd_pool_adapter.c
|
|
@@ -49,7 +49,7 @@ static void *launch_threadtimer_executor(void *arg)
|
|
int scheduing_count;
|
|
|
|
if (tk->eng->proj->start) {
|
|
- if (etmemd_get_task_pids(tk) != 0) {
|
|
+ if (etmemd_get_task_pids(tk, true) != 0) {
|
|
return NULL;
|
|
}
|
|
|
|
diff --git a/src/etmemd_src/etmemd_task.c b/src/etmemd_src/etmemd_task.c
|
|
index 5c81b74..61ba0df 100644
|
|
--- a/src/etmemd_src/etmemd_task.c
|
|
+++ b/src/etmemd_src/etmemd_task.c
|
|
@@ -264,19 +264,13 @@ int get_pid_from_task_type(const struct task *tk, char *pid)
|
|
return -1;
|
|
}
|
|
|
|
-static int get_and_fill_pids(struct task *tk, char *pid)
|
|
+static int fill_task_child_pid(struct task *tk, char *pid)
|
|
{
|
|
char *arg_pid[] = {"/usr/bin/pgrep", "-P", pid, NULL};
|
|
FILE *file = NULL;
|
|
int ret;
|
|
int pipefd[2]; /* used for pipefd[2] communication to obtain the task PID */
|
|
|
|
- /* first, insert the pid of task into the pids list */
|
|
- if (fill_task_pid(tk, pid) != 0) {
|
|
- etmemd_log(ETMEMD_LOG_WARN, "fill task pid fail\n");
|
|
- return -1;
|
|
- }
|
|
-
|
|
if (pipe(pipefd) == -1) {
|
|
return -1;
|
|
}
|
|
@@ -341,7 +335,7 @@ void etmemd_free_task_pids(struct task *tk)
|
|
}
|
|
}
|
|
|
|
-int etmemd_get_task_pids(struct task *tk)
|
|
+int etmemd_get_task_pids(struct task *tk, bool recursive)
|
|
{
|
|
char pid[PID_STR_MAX_LEN] = {0};
|
|
|
|
@@ -356,8 +350,17 @@ int etmemd_get_task_pids(struct task *tk)
|
|
return -1;
|
|
}
|
|
|
|
- /* then fill the pids according to the pid of task */
|
|
- if (get_and_fill_pids(tk, pid) != 0) {
|
|
+ /* first, insert the pid of task into the pids list */
|
|
+ if (fill_task_pid(tk, pid) != 0) {
|
|
+ etmemd_log(ETMEMD_LOG_WARN, "fill task pid fail\n");
|
|
+ return -1;
|
|
+ }
|
|
+ if (!recursive) {
|
|
+ return 0;
|
|
+ }
|
|
+
|
|
+ /* then fill the child pids according to the pid of task */
|
|
+ if (fill_task_child_pid(tk, pid) != 0) {
|
|
etmemd_free_task_pids(tk);
|
|
etmemd_log(ETMEMD_LOG_WARN, "get task child pids fail\n");
|
|
return -1;
|
|
--
|
|
2.27.0
|
|
|