]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
Fix a warning in api.c, where we ignore the fscanf value.
authorBalbir Singh <balbir@linux.vnet.ibm.com>
Sat, 20 Sep 2008 00:54:04 +0000 (00:54 +0000)
committerBalbir Singh <balbir@linux.vnet.ibm.com>
Sat, 20 Sep 2008 00:54:04 +0000 (00:54 +0000)
I've tested the patch by running the tests available in the tests
directory.

Signed-off-by: Balbir Singh <balbir@linux.vnet.ibm.com>
git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/trunk@185 4f4bb910-9a46-0410-90c8-c897d4f1cd53

api.c

diff --git a/api.c b/api.c
index 99037e8f0119b6220fdadeda93f77d3c45ad25c8..fef34c100c3b91d885eadab4facf9474007eedb3 100644 (file)
--- a/api.c
+++ b/api.c
@@ -902,6 +902,7 @@ static char *cg_rd_ctrl_file(char *subsys, char *cgroup, char *file)
        char *value;
        char path[FILENAME_MAX];
        FILE *ctrl_file;
+       int ret;
 
        if (!cg_build_path_locked(cgroup, path, subsys))
                return NULL;
@@ -919,7 +920,11 @@ static char *cg_rd_ctrl_file(char *subsys, char *cgroup, char *file)
         * using %as crashes when we try to read from files like
         * memory.stat
         */
-       fscanf(ctrl_file, "%s", value);
+       ret = fscanf(ctrl_file, "%s", value);
+       if (ret == 0 || ret == EOF) {
+               free(value);
+               value = NULL;
+       }
 
        fclose(ctrl_file);