etmem/0088-etmem-fix-multiple-etmemd-and-too-many-err-log-probl.patch
liubo ab68896f27 etmem: backport bugfix patch from upstream
1. remove unnecessary log code during the
permission check.
2. fix memory leak and fp leak.
3. fix multiple etmemd and too many err log problem.

Signed-off-by: liubo <liubo254@huawei.com>
(cherry picked from commit 7c109accd61df6d6b12b4aff89445acecd3ee555)
2023-06-14 09:21:57 +08:00

75 lines
2.4 KiB
Diff

From 5ca2bdd61980b8cf501bc9397611260f4745a7e6 Mon Sep 17 00:00:00 2001
From: liubo <liubo254@huawei.com>
Date: Tue, 6 Jun 2023 21:14:35 +0800
Subject: [PATCH 4/4] etmem: fix multiple etmemd and too many err log problem
1. the etmem uses the fork and exec mode to run the
feature command to botain the corresponding process information.
If the cmd does not exist, the fork subprocess may not
exit, but the parent process is suspended.
As a result, new etmemd processes are continuously started.
Signed-off-by: liubo <liubo254@huawei.com>
---
etmem/src/etmemd_src/etmemd_task.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/etmem/src/etmemd_src/etmemd_task.c b/etmem/src/etmemd_src/etmemd_task.c
index dfe911f..a50c78d 100644
--- a/etmem/src/etmemd_src/etmemd_task.c
+++ b/etmem/src/etmemd_src/etmemd_task.c
@@ -48,26 +48,33 @@ static int get_pid_through_pipe(char *arg_pid[], const int *pipefd)
if (stdout_copy_fd < 0) {
etmemd_log(ETMEMD_LOG_ERR, "dup(STDOUT_FILENO) fail.\n");
close(pipefd[1]);
- return -1;
+ exit(SIGPIPE);
}
ret = dup2(pipefd[1], fileno(stdout));
if (ret == -1) {
etmemd_log(ETMEMD_LOG_ERR, "dup2 pipefd fail.\n");
close(pipefd[1]);
- return -1;
+ exit(SIGPIPE);
+ }
+
+ ret = dup2(pipefd[1], fileno(stderr));
+ if (ret == -1) {
+ etmemd_log(ETMEMD_LOG_ERR, "dup2 piped fail.\n");
+ close(pipefd[1]);
+ exit(SIGPIPE);
}
if (execve(arg_pid[0], arg_pid, NULL) == -1) {
etmemd_log(ETMEMD_LOG_ERR, "execve %s fail with %s.\n", arg_pid[0], strerror(errno));
close(pipefd[1]);
- return -1;
+ exit(SIGPIPE);
}
- if (fflush(stdout) != 0) {
+ if (fflush(stdout) != 0 || fflush(stderr) != 0) {
etmemd_log(ETMEMD_LOG_ERR, "fflush execve stdout fail.\n");
close(pipefd[1]);
- return -1;
+ exit(SIGPIPE);
}
close(pipefd[1]);
dup2(stdout_copy_fd, fileno(stdout));
@@ -75,6 +82,10 @@ static int get_pid_through_pipe(char *arg_pid[], const int *pipefd)
/* wait for execve done */
wait(&status);
+ if ((WIFEXITED(status) && WEXITSTATUS(status) == SIGPIPE) ||
+ !WIFEXITED(status)) {
+ return -1;
+ }
return 0;
}
--
2.33.0