* Ken'ichi Ohmichi <[email protected]> [2009-12-02 08:46:51]:
>
> Hi Balbir,
>
> If writing an invalid value on a file of cgroup fs, write(2) returns -1
> with a right errno. But fprintf(3) does not return it, because fprintf(3)
> write on some buffer. So it is better that we check the return value of
> write(2).
>
Hi, Kenichi,
Does the code fragment (diff) below work for you?
Please note, it is not an appliable diff, it is a part of bigger
patch.
static int cg_set_control_value(char *path, char *val)
{
+ int ret = 0;
FILE *control_file = NULL;
if (!cg_test_mounted_fs())
return ECGROUPNOTMOUNTED;
@@ -1078,9 +1080,14 @@ static int cg_set_control_value(char *path, char *val)
return ECGROUPVALUENOTEXIST;
}
- fprintf(control_file, "%s", val);
+ ret = fprintf(control_file, "%s", val);
+ if (ret < 0 || ret < strlen(val) + 1) {
+ last_errno = errno;
+ ret = ECGOTHER;
+ } else
+ ret = 0;
fclose(control_file);
- return 0;
+ return ret;
}
--
Balbir
------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing.
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
Libcg-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libcg-devel