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

this also avoid to call two times get_cgroup_mount

Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
---
 src/lxc/cgroup.c |   17 +++++------------
 src/lxc/cgroup.h |    5 +++--
 src/lxc/start.c  |    3 ++-
 src/lxc/start.h  |    1 +
 4 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/src/lxc/cgroup.c b/src/lxc/cgroup.c
index 3711eee..c19e58d 100644
--- a/src/lxc/cgroup.c
+++ b/src/lxc/cgroup.c
@@ -81,10 +81,10 @@ out:
         return err;
 }

-int lxc_rename_nsgroup(const char *name, pid_t pid)
+int lxc_rename_nsgroup(const char *name, struct lxc_handler *handler)
 {
 	char oldname[MAXPATHLEN];
-	char newname[MAXPATHLEN];
+	char *newname = handler->nsgroup;
 	char cgroup[MAXPATHLEN];
 	int ret;

@@ -93,7 +93,7 @@ int lxc_rename_nsgroup(const char *name, pid_t pid)
 		return -1;
 	}

-	snprintf(oldname, MAXPATHLEN, "%s/%d", cgroup, pid);
+	snprintf(oldname, MAXPATHLEN, "%s/%d", cgroup, handler->pid);
 	snprintf(newname, MAXPATHLEN, "%s/%s", cgroup, name);

 	/* there is a previous cgroup, assume it is empty, otherwise
@@ -113,23 +113,16 @@ int lxc_rename_nsgroup(const char *name, pid_t pid)
 	else
 		DEBUG("'%s' renamed to '%s'", oldname, newname);

+
 	return ret;
 }

-int lxc_link_nsgroup(const char *name)
+int lxc_link_nsgroup(const char *name, const char *nsgroup)
 {
 	char lxc[MAXPATHLEN];
-	char nsgroup[MAXPATHLEN];
-	char cgroup[MAXPATHLEN];
 	int ret;

-	if (get_cgroup_mount(MTAB, cgroup)) {
-		ERROR("cgroup is not mounted");
-		return -1;
-	}
-
 	snprintf(lxc, MAXPATHLEN, LXCPATH "/%s/nsgroup", name);
-	snprintf(nsgroup, MAXPATHLEN, "%s/%s", cgroup, name);

 	unlink(lxc);
 	ret = symlink(nsgroup, lxc);
diff --git a/src/lxc/cgroup.h b/src/lxc/cgroup.h
index ad9802e..6863247 100644
--- a/src/lxc/cgroup.h
+++ b/src/lxc/cgroup.h
@@ -25,9 +25,10 @@

 #define MAXPRIOLEN 24

+struct lxc_handler;
 int lxc_get_cgroup_mount(const char *mtab, char *mnt);
-int lxc_rename_nsgroup(const char *name, pid_t pid);
-int lxc_link_nsgroup(const char *name);
+int lxc_rename_nsgroup(const char *name, struct lxc_handler *handler);
+int lxc_link_nsgroup(const char *name, const char *nsgroup);
 int lxc_unlink_nsgroup(const char *name);

 #endif
diff --git a/src/lxc/start.c b/src/lxc/start.c
index b7c8903..a2d931e 100644
--- a/src/lxc/start.c
+++ b/src/lxc/start.c
@@ -424,7 +424,8 @@ int lxc_spawn(const char *name, struct lxc_handler *handler, char *const argv[])
 		goto out_abort;
 	}

-	if (lxc_rename_nsgroup(name, handler->pid) || lxc_link_nsgroup(name))
+	if (lxc_rename_nsgroup(name, handler) ||
+	    lxc_link_nsgroup(name, handler->nsgroup))
 		goto out_abort;

 	/* Create the network configuration */
diff --git a/src/lxc/start.h b/src/lxc/start.h
index a2ab313..bb86f40 100644
--- a/src/lxc/start.h
+++ b/src/lxc/start.h
@@ -29,6 +29,7 @@ struct lxc_handler {
 	int sigfd;
 	int lock;
 	char tty[MAXPATHLEN];
+	char nsgroup[MAXPATHLEN];
 	sigset_t oldmask;
 	struct lxc_tty_info tty_info;
 };
-- 
1.6.3.3

-- 

--===============2056854397==
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

--===============2056854397==--




