From: Michel Normand Date: Fri, 9 Oct 2009 09:38:39 +0000 (+0200) Subject: place nscgroup path in lxc_handler X-Git-Tag: lxc_0_6_4~65 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=758437c558fbfb7fdce3579423e1fc5a9e03c1f3;p=thirdparty%2Flxc.git place nscgroup path in lxc_handler this also avoid to call two times get_cgroup_mount Signed-off-by: Michel Normand Signed-off-by: Daniel Lezcano --- diff --git a/src/lxc/cgroup.c b/src/lxc/cgroup.c index 3711eee65..57db73483 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 ad9802ec2..686324786 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 2e648b730..1e2a28f0b 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 a2ab31377..bb86f404a 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; };