[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH] LXC fix virCgroupGetValueStr on handling a string terminated with '\n'

Hi there,

A cgroup file returns integer value terminated with '\n' and remaining
it has sometimes harmful effects, for example it leads virStrToLong_ull

The fix just gets rid of '\n' if included. It first has been in
virCgroupGetFreezerState, but now merged in virCgroupGetValueStr to cover
every functions using virCgroupGetValueStr.

I'm not sure that that behavior is from the beginning or changed in a
recent kernel, but the fix should work even though anyway.

BTW, by the defect I first got the following error and it made me confused.

# virsh -c lxc:/// dominfo 4930
Id:             4930
Name:           lxc
UUID:           084369a0-956a-3010-fc37-ddeb4d627e69
OS Type:        exe
Autostart:      disable
error: this function is not supported by the hypervisor: virNodeGetSecurityModel

The really error happens in lxcDomainGetInfo, so I guess something is wrong
with internal error propagation. Anyone know this unexpected behavior?


>From 667efde6ad165479817975c6544f6784e1177a32 Mon Sep 17 00:00:00 2001
From: Ryota Ozaki <ozaki ryota gmail com>
Date: Fri, 16 Oct 2009 00:13:41 +0900
Subject: [PATCH] LXC fix virCgroupGetValueStr on handling a string
terminated with '\n'

* src/util/cgroup.c: get rid of '\n' from the return value
  of virCgroupGetValueStr
 src/util/cgroup.c |   12 +++++-------
 1 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/src/util/cgroup.c b/src/util/cgroup.c
index f728a2f..f0e2960 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((const char *)value, '\n');
+        if (p) *p = '\0';
         rc = 0;

@@ -969,13 +973,7 @@ int virCgroupSetFreezerState(virCgroupPtr group, const char

 int virCgroupGetFreezerState(virCgroupPtr group, char **state)
-    int ret;
-    ret = virCgroupGetValueStr(group,
+    return virCgroupGetValueStr(group,
                                 "freezer.state", state);
-    if (ret == 0) {
-        char *p = strchr(*state, '\n');
-        if (p) *p = '\0';
-    }
-    return ret;

Attachment: 0001-LXC-fix-virCgroupGetValueStr-on-handling-a-string-te.patch
Description: Binary data

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]