1 Star 0 Fork 9

wuzx/lxcfs

forked from src-openEuler/lxcfs 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0005-fix-concurrency-problem.patch 3.07 KB
一键复制 编辑 原始数据 按行查看 历史
vegbir 提交于 2023-07-27 09:31 . upgrade to 5.0.4
From a7f9759ef8ce354ab2ad420d4a8c5b4260d491fc Mon Sep 17 00:00:00 2001
From: vegbir <[email protected]>
Date: Thu, 27 Jul 2023 07:24:18 +0000
Subject: [PATCH 05/15] fix concurrency problem
Signed-off-by: vegbir <[email protected]>
---
src/cgroups/cgroup_utils.c | 21 +++++++++++++--------
src/cgroups/cgroup_utils.h | 2 +-
src/proc_fuse.c | 3 +++
3 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/src/cgroups/cgroup_utils.c b/src/cgroups/cgroup_utils.c
index 83e4cbf..1224971 100644
--- a/src/cgroups/cgroup_utils.c
+++ b/src/cgroups/cgroup_utils.c
@@ -512,23 +512,28 @@ static char *copy_to_eol(char *p)
return sret;
}
-static void batch_realloc(char **mem, size_t oldlen, size_t newlen)
+char *batch_realloc(char *mem, size_t oldlen, size_t newlen)
{
int newbatches = (newlen / BATCH_SIZE) + 1;
int oldbatches = (oldlen / BATCH_SIZE) + 1;
- if (!*mem || newbatches > oldbatches) {
- *mem = must_realloc(*mem, newbatches * BATCH_SIZE);
+ if (!mem || newbatches > oldbatches) {
+ char *tmp;
+ tmp = must_realloc(mem, newbatches * BATCH_SIZE);
+ return tmp;
}
+ return mem;
}
-void append_line(char **dest, size_t oldlen, char *new, size_t newlen)
+char *append_line(char *dest, size_t oldlen, char *new, size_t newlen)
{
+ char *tmp;
size_t full = oldlen + newlen;
- batch_realloc(dest, oldlen, full + 1);
+ tmp = batch_realloc(dest, oldlen, full + 1);
- memcpy(*dest + oldlen, new, newlen + 1);
+ memcpy(tmp + oldlen, new, newlen + 1);
+ return tmp;
}
static inline void drop_trailing_newlines(char *s)
@@ -552,7 +557,7 @@ char *read_file(const char *fnam)
if (!f)
return NULL;
while ((linelen = getline(&line, &len, f)) != -1) {
- append_line(&buf, fulllen, line, linelen);
+ buf = append_line(buf, fulllen, line, linelen);
fulllen += linelen;
}
return buf;
@@ -682,7 +687,7 @@ char *readat_file(int dirfd, const char *path)
move_fd(fd);
while ((linelen = getline(&line, &len, f)) != -1) {
- append_line(&buf, fulllen, line, linelen);
+ buf = append_line(buf, fulllen, line, linelen);
fulllen += linelen;
}
diff --git a/src/cgroups/cgroup_utils.h b/src/cgroups/cgroup_utils.h
index f431686..d4c8598 100644
--- a/src/cgroups/cgroup_utils.h
+++ b/src/cgroups/cgroup_utils.h
@@ -70,7 +70,7 @@ extern size_t strlcat(char *d, const char *s, size_t n);
#endif
extern FILE *fopen_cloexec(const char *path, const char *mode);
-extern void append_line(char **dest, size_t oldlen, char *new, size_t newlen);
+extern char *append_line(char *dest, size_t oldlen, char *new, size_t newlen);
extern char *read_file(const char *fnam);
extern char *readat_file(int fd, const char *path);
extern char *read_file_strip_newline(const char *fnam);
diff --git a/src/proc_fuse.c b/src/proc_fuse.c
index ed70ea7..0af559f 100644
--- a/src/proc_fuse.c
+++ b/src/proc_fuse.c
@@ -1747,6 +1747,9 @@ __lxcfs_fuse_ops int proc_read(const char *path, char *buf, size_t size,
{
struct file_info *f = INTTYPE_TO_PTR(fi->fh);
+ if (!f->buf)
+ return -EINVAL;
+
switch (f->type) {
case LXC_TYPE_PROC_MEMINFO:
if (liblxcfs_functional())
--
2.41.0
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wuzx065891/lxcfs.git
[email protected]:wuzx065891/lxcfs.git
wuzx065891
lxcfs
lxcfs
master

搜索帮助