]> git.pld-linux.org Git - packages/libcgroup.git/blob - libcgroup-0.40.rc1-fread.patch
- new Source0, updated to 0.42.2
[packages/libcgroup.git] / libcgroup-0.40.rc1-fread.patch
1 diff --git a/src/api.c b/src/api.c
2 index 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,
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  
24         *value = calloc(CG_CONTROL_VALUE_MAX, 1);
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          */
37 -       ret = fread(*value, 1, CG_CONTROL_VALUE_MAX-1, ctrl_file);
38 +       ret = read(ctrl_file, *value, CG_CONTROL_VALUE_MAX-1);
39         if (ret < 0) {
40                 free(*value);
41                 *value = NULL;
42 @@ -2514,7 +2514,7 @@ static int cg_rd_ctrl_file(const char *subsys, const char *cgroup,
43                         (*value)[ret-1] = '\0';
44         }
45  
46 -       fclose(ctrl_file);
47 +       close(ctrl_file);
48  
49         return 0;
50  }
This page took 0.063259 seconds and 3 git commands to generate.