]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
LXC fix virCgroupGetValueStr problem with \n
authorRyota Ozaki <ozaki.ryota@gmail.com>
Mon, 19 Oct 2009 12:29:42 +0000 (14:29 +0200)
committerDaniel Veillard <veillard@redhat.com>
Mon, 19 Oct 2009 12:29:42 +0000 (14:29 +0200)
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

index f728a2f596b78fe13305581e301385d78dc704ae..bdd4eb68edb18570a8b48adcbd8d0d7750d646c8 100644 (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;
 }