]> git.pld-linux.org Git - packages/libcgroup.git/blame - libcgroup-0.40.rc1-fread.patch
- new Source0, updated to 0.42.2
[packages/libcgroup.git] / libcgroup-0.40.rc1-fread.patch
CommitLineData
51630b4e
JB
1diff --git a/src/api.c b/src/api.c
2index 54a6736..1557393 100644
3--- a/src/api.c
4+++ b/src/api.c
5@@ -2482,29 +2482,29 @@ static int cg_rd_ctrl_file(const char *subsys, const char *cgroup,
9665627f
AM
6 const char *file, char **value)
7 {
8 char path[FILENAME_MAX];
9- FILE *ctrl_file = NULL;
10- int ret;
11+ int ctrl_file = -1;
12+ ssize_t ret;
13
14 if (!cg_build_path_locked(cgroup, path, subsys))
15 return ECGFAIL;
16
17 strncat(path, file, sizeof(path) - strlen(path));
18- ctrl_file = fopen(path, "re");
19- if (!ctrl_file)
20+ ctrl_file = open(path, O_RDONLY | O_CLOEXEC);
21+ if (ctrl_file < 0)
22 return ECGROUPVALUENOTEXIST;
23
51630b4e 24 *value = calloc(CG_CONTROL_VALUE_MAX, 1);
9665627f
AM
25 if (!*value) {
26- fclose(ctrl_file);
27+ close(ctrl_file);
28 last_errno = errno;
29 return ECGOTHER;
30 }
31
32 /*
33- * using %as crashes when we try to read from files like
34+ * using %as or fread crashes when we try to read from files like
35 * memory.stat
36 */
51630b4e
JB
37- ret = fread(*value, 1, CG_CONTROL_VALUE_MAX-1, ctrl_file);
38+ ret = read(ctrl_file, *value, CG_CONTROL_VALUE_MAX-1);
9665627f
AM
39 if (ret < 0) {
40 free(*value);
41 *value = NULL;
51630b4e 42@@ -2514,7 +2514,7 @@ static int cg_rd_ctrl_file(const char *subsys, const char *cgroup,
9665627f
AM
43 (*value)[ret-1] = '\0';
44 }
45
46- fclose(ctrl_file);
47+ close(ctrl_file);
48
49 return 0;
50 }
This page took 0.093964 seconds and 4 git commands to generate.