From: Ken'ichi Ohmichi Date: Thu, 28 Jan 2010 05:45:48 +0000 (+0530) Subject: [PATCH-v2] Add the write error handling to cg_set_control_value(). X-Git-Tag: v0.36.2~23 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c05a25c145d1584299ecdfe8f941bc8658c809b7;p=thirdparty%2Flibcgroup.git [PATCH-v2] Add the write error handling to cg_set_control_value(). Changelog since v1: o Use fopen/fprintf/fclose instead of open/write/close. o Add the error handling against fclose. 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 add the error handling for knowing it. Signed-off-by: Ken'ichi Ohmichi Signed-off-by: Balbir Singh --- diff --git a/src/api.c b/src/api.c index 4a7185b6..cd2e298b 100644 --- a/src/api.c +++ b/src/api.c @@ -1089,8 +1089,15 @@ static int cg_set_control_value(char *path, char *val) return ECGROUPVALUENOTEXIST; } - fprintf(control_file, "%s", val); - fclose(control_file); + if (fprintf(control_file, "%s", val) < 0) { + last_errno = errno; + fclose(control_file); + return ECGOTHER; + } + if (fclose(control_file) < 0) { + last_errno = errno; + return ECGOTHER; + } return 0; }