1 Star 0 Fork 7

wangkang101 / lxcfs

forked from src-openEuler / lxcfs 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0006-fix-concurrency-problem.patch 2.64 KB
一键复制 编辑 原始数据 按行查看 历史
wangkang101 提交于 2020-08-28 15:17 . update to 4.0.5
diff --git a/src/cgroups/cgroup_utils.c b/src/cgroups/cgroup_utils.c
index 078f864..c21e7bc 100644
--- a/src/cgroups/cgroup_utils.c
+++ b/src/cgroups/cgroup_utils.c
@@ -521,23 +521,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)
@@ -561,7 +566,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;
@@ -691,7 +696,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 d1f5639..a40bdf5 100644
--- a/src/cgroups/cgroup_utils.h
+++ b/src/cgroups/cgroup_utils.h
@@ -79,7 +79,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 6b503d6..334f6ea 100644
--- a/src/proc_fuse.c
+++ b/src/proc_fuse.c
@@ -1403,6 +1403,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())
1
https://gitee.com/wangkang101/lxcfs.git
git@gitee.com:wangkang101/lxcfs.git
wangkang101
lxcfs
lxcfs
master

搜索帮助