From: François-Xavier Bourlet Date: Tue, 22 Mar 2011 14:10:37 +0000 (+0100) Subject: lxc_cgroup_path_get, cache the right value X-Git-Tag: lxc-0.7.5~44 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0411a75203ef20037ff5d9ac59c10ca5890e8fc8;p=thirdparty%2Flxc.git lxc_cgroup_path_get, cache the right value lxc_cgroup_path_get currently cache the cgroup mount point plus the container name at the same time, making every call of the function returning the same value. It mean that actually every call to lxc_cgroup_get with a different container name will in fact use the same container name as used for the primary call. I join a patch to fix that, still doing some caching, but only caching the cgroup moint point this time. This patch actually work for me, as I am using the liblxc for retrieving statistics about all running containers, using lxc_cgroup_get to retrieve every interesting values. Signed-off-by: Daniel Lezcano --- diff --git a/src/lxc/cgroup.c b/src/lxc/cgroup.c index 69761b4d6..a068a0168 100644 --- a/src/lxc/cgroup.c +++ b/src/lxc/cgroup.c @@ -47,8 +47,6 @@ lxc_log_define(lxc_cgroup, lxc); #define MTAB "/proc/mounts" -static char nsgroup_path[MAXPATHLEN]; - enum { CGROUP_NS_CGROUP = 1, CGROUP_CLONE_CHILDREN, @@ -291,22 +289,21 @@ int lxc_cgroup_destroy(const char *name) int lxc_cgroup_path_get(char **path, const char *name) { - char cgroup[MAXPATHLEN]; - - *path = &nsgroup_path[0]; - - /* - * report nsgroup_path string if already set - */ - if (**path != 0) - return 0; - - if (get_cgroup_mount(MTAB, cgroup)) { - ERROR("cgroup is not mounted"); - return -1; + static char cgroup[MAXPATHLEN]; + static const char* cgroup_cached = 0; + static char buf[MAXPATHLEN]; + + if (!cgroup_cached) { + if (get_cgroup_mount(MTAB, cgroup)) { + ERROR("cgroup is not mounted"); + return -1; + } else { + cgroup_cached = cgroup; + } } - snprintf(nsgroup_path, MAXPATHLEN, "%s/%s", cgroup, name); + snprintf(buf, MAXPATHLEN, "%s/%s", cgroup_cached, name); + *path = buf; return 0; }