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

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

 



Hi there,

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

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?

Thanks,
  ozaki-r

>From 667efde6ad165479817975c6544f6784e1177a32 Mon Sep 17 00:00:00 2001
From: Ryota Ozaki <ozaki.ryota@xxxxxxxxx>
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
 *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;
 }
-- 
1.6.2.5

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

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]