Commit 758437c5 by Michel Normand Committed by Daniel Lezcano

place nscgroup path in lxc_handler

this also avoid to call two times get_cgroup_mount Signed-off-by: 's avatarMichel Normand <normand@fr.ibm.com> Signed-off-by: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com>
parent 52e35957
...@@ -81,10 +81,10 @@ out: ...@@ -81,10 +81,10 @@ out:
return err; 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 oldname[MAXPATHLEN];
char newname[MAXPATHLEN]; char *newname = handler->nsgroup;
char cgroup[MAXPATHLEN]; char cgroup[MAXPATHLEN];
int ret; int ret;
...@@ -93,7 +93,7 @@ int lxc_rename_nsgroup(const char *name, pid_t pid) ...@@ -93,7 +93,7 @@ int lxc_rename_nsgroup(const char *name, pid_t pid)
return -1; return -1;
} }
snprintf(oldname, MAXPATHLEN, "%s/%d", cgroup, pid); snprintf(oldname, MAXPATHLEN, "%s/%d", cgroup, handler->pid);
snprintf(newname, MAXPATHLEN, "%s/%s", cgroup, name); snprintf(newname, MAXPATHLEN, "%s/%s", cgroup, name);
/* there is a previous cgroup, assume it is empty, otherwise /* there is a previous cgroup, assume it is empty, otherwise
...@@ -113,23 +113,16 @@ int lxc_rename_nsgroup(const char *name, pid_t pid) ...@@ -113,23 +113,16 @@ int lxc_rename_nsgroup(const char *name, pid_t pid)
else else
DEBUG("'%s' renamed to '%s'", oldname, newname); DEBUG("'%s' renamed to '%s'", oldname, newname);
return ret; return ret;
} }
int lxc_link_nsgroup(const char *name) int lxc_link_nsgroup(const char *name, const char *nsgroup)
{ {
char lxc[MAXPATHLEN]; char lxc[MAXPATHLEN];
char nsgroup[MAXPATHLEN];
char cgroup[MAXPATHLEN];
int ret; int ret;
if (get_cgroup_mount(MTAB, cgroup)) {
ERROR("cgroup is not mounted");
return -1;
}
snprintf(lxc, MAXPATHLEN, LXCPATH "/%s/nsgroup", name); snprintf(lxc, MAXPATHLEN, LXCPATH "/%s/nsgroup", name);
snprintf(nsgroup, MAXPATHLEN, "%s/%s", cgroup, name);
unlink(lxc); unlink(lxc);
ret = symlink(nsgroup, lxc); ret = symlink(nsgroup, lxc);
......
...@@ -25,9 +25,10 @@ ...@@ -25,9 +25,10 @@
#define MAXPRIOLEN 24 #define MAXPRIOLEN 24
struct lxc_handler;
int lxc_get_cgroup_mount(const char *mtab, char *mnt); int lxc_get_cgroup_mount(const char *mtab, char *mnt);
int lxc_rename_nsgroup(const char *name, pid_t pid); int lxc_rename_nsgroup(const char *name, struct lxc_handler *handler);
int lxc_link_nsgroup(const char *name); int lxc_link_nsgroup(const char *name, const char *nsgroup);
int lxc_unlink_nsgroup(const char *name); int lxc_unlink_nsgroup(const char *name);
#endif #endif
...@@ -424,7 +424,8 @@ int lxc_spawn(const char *name, struct lxc_handler *handler, char *const argv[]) ...@@ -424,7 +424,8 @@ int lxc_spawn(const char *name, struct lxc_handler *handler, char *const argv[])
goto out_abort; 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; goto out_abort;
/* Create the network configuration */ /* Create the network configuration */
......
...@@ -29,6 +29,7 @@ struct lxc_handler { ...@@ -29,6 +29,7 @@ struct lxc_handler {
int sigfd; int sigfd;
int lock; int lock;
char tty[MAXPATHLEN]; char tty[MAXPATHLEN];
char nsgroup[MAXPATHLEN];
sigset_t oldmask; sigset_t oldmask;
struct lxc_tty_info tty_info; struct lxc_tty_info tty_info;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment