From 41fa653f322805b0a492205f91abebe09d594cc0 Mon Sep 17 00:00:00 2001 From: Ryota Ozaki Date: Mon, 19 Oct 2009 14:29:42 +0200 Subject: [PATCH] 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 --- src/util/cgroup.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/util/cgroup.c b/src/util/cgroup.c index f728a2f596..bdd4eb68ed 100644 --- a/src/util/cgroup.c +++ b/src/util/cgroup.c @@ -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; }