Hi,

cg_set_control_value() is the function for setting a value to a file
of cgroup file system. And current function does not handle the error
of writing to a file. So we cannot know whether setting value is
enable or not.

This patch adds the error handling for knowing it.
    

Thanks
Ken'ichi Ohmichi

Signed-off-by: Ken'ichi Ohmichi <[email protected]>

diff --git a/src/api.c b/src/api.c
index 28c0c3d..5481dbd 100644
--- a/src/api.c
+++ b/src/api.c
@@ -1046,13 +1046,13 @@ static int cg_create_control_group(char *path)
  */
 static int cg_set_control_value(char *path, char *val)
 {
-       FILE *control_file = NULL;
+       int control_file;
        if (!cg_test_mounted_fs())
                return ECGROUPNOTMOUNTED;
 
-       control_file = fopen(path, "r+");
+       control_file = open(path, O_RDWR);
 
-       if (!control_file) {
+       if (control_file < 0) {
                if (errno == EPERM) {
                        /*
                         * We need to set the correct error value, does the
@@ -1067,19 +1067,23 @@ static int cg_set_control_value(char *path, char *val)
                                len--;
                        *(path+len+1) = '\0';
                        strncat(path, "tasks", sizeof(path) - strlen(path));
-                       control_file = fopen(path, "r");
-                       if (!control_file) {
+                       control_file = open(path, O_RDONLY);
+                       if (control_file < 0) {
                                if (errno == ENOENT)
                                        return ECGROUPSUBSYSNOTMOUNTED;
                        }
-                       fclose(control_file);
+                       close(control_file);
                        return ECGROUPNOTALLOWED;
                }
                return ECGROUPVALUENOTEXIST;
        }
 
-       fprintf(control_file, "%s", val);
-       fclose(control_file);
+       if (write(control_file, val, strlen(val) + 1) < 0) {
+               last_errno = errno;
+               close(control_file);
+               return ECGOTHER;
+       }
+       close(control_file);
        return 0;
 }
 

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Libcg-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to