From: Michel Normand <normand@fr.ibm.com>

remove the usage of LXCPATH/<name>/nsgroup
in get/set function.

Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
---
 src/lxc/cgroup.c |   37 +++++++++++++++++++++++++++++++++++--
 1 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/src/lxc/cgroup.c b/src/lxc/cgroup.c
index c19e58d..c3f74c1 100644
--- a/src/lxc/cgroup.c
+++ b/src/lxc/cgroup.c
@@ -45,6 +45,8 @@ lxc_log_define(lxc_cgroup, lxc);

 #define MTAB "/etc/mtab"

+static char nsgroup_path[MAXPATHLEN];
+
 static int get_cgroup_mount(const char *mtab, char *mnt)
 {
         struct mntent *mntent;
@@ -153,12 +155,38 @@ int lxc_unlink_nsgroup(const char *name)
 	return unlink(nsgroup);
 }

+static 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;
+	}
+
+	snprintf(nsgroup_path, MAXPATHLEN, "%s/%s", cgroup, name);
+	return 0;
+}
+
 int lxc_cgroup_set(const char *name, const char *subsystem, const char *value)
 {
 	int fd, ret = -1;
+	char *nsgroup;
 	char path[MAXPATHLEN];

-        snprintf(path, MAXPATHLEN, LXCPATH "/%s/nsgroup/%s", name, subsystem);
+	ret = lxc_cgroup_path_get(&nsgroup, name);
+	if (ret)
+		return -1;
+
+        snprintf(path, MAXPATHLEN, "%s/%s", nsgroup, subsystem);

 	fd = open(path, O_WRONLY);
 	if (fd < 0) {
@@ -181,9 +209,14 @@ int lxc_cgroup_get(const char *name, const char *subsystem,
 		   char *value, size_t len)
 {
 	int fd, ret = -1;
+	char *nsgroup;
 	char path[MAXPATHLEN];

-        snprintf(path, MAXPATHLEN, LXCPATH "/%s/nsgroup/%s", name, subsystem);
+	ret = lxc_cgroup_path_get(&nsgroup, name);
+	if (ret)
+		return -1;
+
+        snprintf(path, MAXPATHLEN, "%s/%s", nsgroup, subsystem);

 	fd = open(path, O_RDONLY);
 	if (fd < 0) {
-- 
1.6.3.3

-- 

--===============2133698283==
Content-Type: text/plain; charset="iso-8859-1"
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

_______________________________________________
Linux mailing list
Linux@www.lab.toulouse-stg.fr.ibm.com
http://www.lab.toulouse-stg.fr.ibm.com/mailman/listinfo/linux

--===============2133698283==--




