1 Star 0 Fork 17

wangfengtu/libcgroup

forked from src-openEuler/libcgroup 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
libcgroup-0.40.rc1-fread.patch 1.30 KB
一键复制 编辑 原始数据 按行查看 历史
zklei 提交于 2020-11-04 10:58 . libcgroup: new upstream release 0.42.2
diff --git libcgroup-0.42.2/src/api.c libcgroup-0.42.2/src/api.c
index 54a6736..1557393 100644
--- libcgroup-0.42.2/src/api.c
+++ libcgroup-0.42.2/src/api.c
@@ -2482,29 +2482,29 @@ static int cg_rd_ctrl_file(const char *subsys, const char *cgroup,
const char *file, char **value)
{
char path[FILENAME_MAX];
- FILE *ctrl_file = NULL;
- int ret;
+ int ctrl_file = -1;
+ ssize_t ret;
if (!cg_build_path_locked(cgroup, path, subsys))
return ECGFAIL;
strncat(path, file, sizeof(path) - strlen(path));
- ctrl_file = fopen(path, "re");
- if (!ctrl_file)
+ ctrl_file = open(path, O_RDONLY | O_CLOEXEC);
+ if (ctrl_file < 0)
return ECGROUPVALUENOTEXIST;
*value = calloc(CG_CONTROL_VALUE_MAX, 1);
if (!*value) {
- fclose(ctrl_file);
+ close(ctrl_file);
last_errno = errno;
return ECGOTHER;
}
/*
- * using %as crashes when we try to read from files like
+ * using %as or fread crashes when we try to read from files like
* memory.stat
*/
- ret = fread(*value, 1, CG_CONTROL_VALUE_MAX-1, ctrl_file);
+ ret = read(ctrl_file, *value, CG_CONTROL_VALUE_MAX-1);
if (ret < 0) {
free(*value);
*value = NULL;
@@ -2514,7 +2514,7 @@ static int cg_rd_ctrl_file(const char *subsys, const char *cgroup,
(*value)[ret-1] = '\0';
}
- fclose(ctrl_file);
+ close(ctrl_file);
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wangfengtu/libcgroup.git
git@gitee.com:wangfengtu/libcgroup.git
wangfengtu
libcgroup
libcgroup
master

搜索帮助