When a group parameter has empty value (like uninitialized cpuset.cpus),
libcgroup does not return this parameter value - it returns
ECGROUPVALUENOTEXIST instead.
I think reading whole parameter file instead of just '%s' is the right thing
to do - it helps also with multiline values, like cpuacct.stat.
Signed-off-by: Jan Safranek <jsafrane@redhat.com>
if (!ctrl_file)
return ECGROUPVALUENOTEXIST;
- *value = malloc(CG_VALUE_MAX);
+ *value = calloc(CG_VALUE_MAX, 1);
if (!*value) {
last_errno = errno;
return ECGOTHER;
* using %as crashes when we try to read from files like
* memory.stat
*/
- ret = fscanf(ctrl_file, "%s", *value);
- if (ret == 0 || ret == EOF) {
+ ret = fread(*value, 1, CG_VALUE_MAX-1, ctrl_file);
+ if (ret < 0) {
free(*value);
*value = NULL;
+ } else {
+ /* remove trailing \n */
+ if (ret > 0 && (*value)[ret-1] == '\n')
+ (*value)[ret-1] = '\0';
}
fclose(ctrl_file);