From: Ryota Ozaki Date: Mon, 19 Oct 2009 12:29:42 +0000 (+0200) Subject: LXC fix virCgroupGetValueStr problem with \n X-Git-Tag: v0.7.3~209 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=41fa653f322805b0a492205f91abebe09d594cc0;p=thirdparty%2Flibvirt.git 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 --- 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; }