未验证 提交 ad39459b 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #7499 from taosdata/fix/TD-6164

[TD-6164]<fix>: fix deadlock with fopen's malloc
...@@ -44,14 +44,20 @@ char cmdline[1024]; ...@@ -44,14 +44,20 @@ char cmdline[1024];
char* taosGetCmdlineByPID(int pid) { char* taosGetCmdlineByPID(int pid) {
sprintf(cmdline, "/proc/%d/cmdline", pid); sprintf(cmdline, "/proc/%d/cmdline", pid);
FILE* f = fopen(cmdline, "r");
if (f) { int fd = open(cmdline, O_RDONLY);
size_t size; if (fd >= 0) {
size = fread(cmdline, sizeof(char), 1024, f); int n = read(fd, cmdline, sizeof(cmdline) - 1);
if (size > 0) { if (n < 0) n = 0;
if ('\n' == cmdline[size - 1]) cmdline[size - 1] = '\0';
} if (n > 0 && cmdline[n - 1] == '\n') --n;
fclose(f);
cmdline[n] = 0;
close(fd);
} else {
cmdline[0] = 0;
} }
return cmdline; return cmdline;
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册