Blame SOURCES/libcgroup-0.40.rc1-fread.patch
|
|
705669 |
diff -up libcgroup-0.41/src/api.c.fread libcgroup-0.41/src/api.c
|
|
|
705669 |
--- libcgroup-0.41/src/api.c.fread 2014-01-13 21:01:32.067067615 +0100
|
|
|
705669 |
+++ libcgroup-0.41/src/api.c 2014-01-13 21:01:32.070067594 +0100
|
|
|
705669 |
@@ -2232,29 +2232,29 @@ static int cg_rd_ctrl_file(const char *s
|
|
|
da3e87 |
const char *file, char **value)
|
|
|
da3e87 |
{
|
|
|
da3e87 |
char path[FILENAME_MAX];
|
|
|
da3e87 |
- FILE *ctrl_file = NULL;
|
|
|
da3e87 |
- int ret;
|
|
|
da3e87 |
+ int ctrl_file = -1;
|
|
|
da3e87 |
+ ssize_t ret;
|
|
|
da3e87 |
|
|
|
da3e87 |
if (!cg_build_path_locked(cgroup, path, subsys))
|
|
|
da3e87 |
return ECGFAIL;
|
|
|
da3e87 |
|
|
|
da3e87 |
strncat(path, file, sizeof(path) - strlen(path));
|
|
|
da3e87 |
- ctrl_file = fopen(path, "re");
|
|
|
da3e87 |
- if (!ctrl_file)
|
|
|
da3e87 |
+ ctrl_file = open(path, O_RDONLY | O_CLOEXEC);
|
|
|
da3e87 |
+ if (ctrl_file < 0)
|
|
|
da3e87 |
return ECGROUPVALUENOTEXIST;
|
|
|
da3e87 |
|
|
|
da3e87 |
*value = calloc(CG_VALUE_MAX, 1);
|
|
|
da3e87 |
if (!*value) {
|
|
|
da3e87 |
- fclose(ctrl_file);
|
|
|
da3e87 |
+ close(ctrl_file);
|
|
|
da3e87 |
last_errno = errno;
|
|
|
da3e87 |
return ECGOTHER;
|
|
|
da3e87 |
}
|
|
|
da3e87 |
|
|
|
da3e87 |
/*
|
|
|
da3e87 |
- * using %as crashes when we try to read from files like
|
|
|
da3e87 |
+ * using %as or fread crashes when we try to read from files like
|
|
|
da3e87 |
* memory.stat
|
|
|
da3e87 |
*/
|
|
|
da3e87 |
- ret = fread(*value, 1, CG_VALUE_MAX-1, ctrl_file);
|
|
|
da3e87 |
+ ret = read(ctrl_file, *value, CG_VALUE_MAX-1);
|
|
|
da3e87 |
if (ret < 0) {
|
|
|
da3e87 |
free(*value);
|
|
|
da3e87 |
*value = NULL;
|
|
|
705669 |
@@ -2264,7 +2264,7 @@ static int cg_rd_ctrl_file(const char *s
|
|
|
da3e87 |
(*value)[ret-1] = '\0';
|
|
|
da3e87 |
}
|
|
|
da3e87 |
|
|
|
da3e87 |
- fclose(ctrl_file);
|
|
|
da3e87 |
+ close(ctrl_file);
|
|
|
da3e87 |
|
|
|
da3e87 |
return 0;
|
|
|
da3e87 |
}
|