]> git.pld-linux.org Git - packages/libcgroup.git/blob - libcgroup-0.40.rc1-fread.patch
acc7eba3b2a3ece87535e4fff5dc87d553444c74
[packages/libcgroup.git] / libcgroup-0.40.rc1-fread.patch
1 diff -up libcgroup-0.41/src/api.c.fread libcgroup-0.41/src/api.c
2 --- libcgroup-0.41/src/api.c.fread      2014-01-13 21:01:32.067067615 +0100
3 +++ libcgroup-0.41/src/api.c    2014-01-13 21:01:32.070067594 +0100
4 @@ -2232,29 +2232,29 @@ static int cg_rd_ctrl_file(const char *s
5                                         const char *file, char **value)
6  {
7         char path[FILENAME_MAX];
8 -       FILE *ctrl_file = NULL;
9 -       int ret;
10 +       int ctrl_file = -1;
11 +       ssize_t ret;
12  
13         if (!cg_build_path_locked(cgroup, path, subsys))
14                 return ECGFAIL;
15  
16         strncat(path, file, sizeof(path) - strlen(path));
17 -       ctrl_file = fopen(path, "re");
18 -       if (!ctrl_file)
19 +       ctrl_file = open(path, O_RDONLY | O_CLOEXEC);
20 +       if (ctrl_file < 0)
21                 return ECGROUPVALUENOTEXIST;
22  
23         *value = calloc(CG_VALUE_MAX, 1);
24         if (!*value) {
25 -               fclose(ctrl_file);
26 +               close(ctrl_file);
27                 last_errno = errno;
28                 return ECGOTHER;
29         }
30  
31         /*
32 -        * using %as crashes when we try to read from files like
33 +        * using %as or fread crashes when we try to read from files like
34          * memory.stat
35          */
36 -       ret = fread(*value, 1, CG_VALUE_MAX-1, ctrl_file);
37 +       ret = read(ctrl_file, *value, CG_VALUE_MAX-1);
38         if (ret < 0) {
39                 free(*value);
40                 *value = NULL;
41 @@ -2264,7 +2264,7 @@ static int cg_rd_ctrl_file(const char *s
42                         (*value)[ret-1] = '\0';
43         }
44  
45 -       fclose(ctrl_file);
46 +       close(ctrl_file);
47  
48         return 0;
49  }
This page took 0.066994 seconds and 2 git commands to generate.