1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-20 07:59:00 +00:00

LXC fix virCgroupGetValueStr problem with \n

A cgroup file returns integer value terminated with '\n' and remaining
it has sometimes harmful effects, for example it leads virStrToLong_ull
to fail.
* src/util/cgroup.c: strip out terminating \n when reading a value
This commit is contained in:
Ryota Ozaki 2009-10-19 14:29:42 +02:00 committed by Daniel Veillard
parent 4f4a1deccb
commit 41fa653f32

View File

@ -309,6 +309,10 @@ static int virCgroupGetValueStr(virCgroupPtr group,
DEBUG("Failed to read %s: %m\n", keypath);
rc = -errno;
} else {
/* Terminated with '\n' has sometimes harmful effects to the caller */
char *p = strchr(*value, '\n');
if (p) *p = '\0';
rc = 0;
}
@ -969,13 +973,7 @@ int virCgroupSetFreezerState(virCgroupPtr group, const char *state)
int virCgroupGetFreezerState(virCgroupPtr group, char **state)
{
int ret;
ret = virCgroupGetValueStr(group,
return virCgroupGetValueStr(group,
VIR_CGROUP_CONTROLLER_CPU,
"freezer.state", state);
if (ret == 0) {
char *p = strchr(*state, '\n');
if (p) *p = '\0';
}
return ret;
}