Commit 160a0d33 authored by Pavel Emelyanov's avatar Pavel Emelyanov

cgroup: Unshare cgroup namespaces only if we need to

The call to unshare(CLONE_NEWCGROUP) is done unconditionally
in prepare_cgns(), which is wrong -- some detection of the
fact that we have this ns should be there.

This detection (as I see it) -- is whether we've found at
least one cgroup with cgns prefix.
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent 3d955982
...@@ -1018,6 +1018,7 @@ static int userns_move(void *arg, int fd, pid_t pid) ...@@ -1018,6 +1018,7 @@ static int userns_move(void *arg, int fd, pid_t pid)
static int prepare_cgns(CgSetEntry *se) static int prepare_cgns(CgSetEntry *se)
{ {
int i; int i;
bool do_unshare = false;
for (i = 0; i < se->n_ctls; i++) { for (i = 0; i < se->n_ctls; i++) {
char aux[PATH_MAX]; char aux[PATH_MAX];
...@@ -1067,11 +1068,12 @@ static int prepare_cgns(CgSetEntry *se) ...@@ -1067,11 +1068,12 @@ static int prepare_cgns(CgSetEntry *se)
return -1; return -1;
} }
do_unshare = true;
} }
} }
if (unshare(CLONE_NEWCGROUP) < 0) { if (do_unshare && unshare(CLONE_NEWCGROUP) < 0) {
pr_perror("couldn't unshare cgns"); pr_perror("couldn't unshare cgns");
return -1; return -1;
} }
...@@ -1133,7 +1135,6 @@ int prepare_task_cgroup(struct pstree_item *me) ...@@ -1133,7 +1135,6 @@ int prepare_task_cgroup(struct pstree_item *me)
{ {
CgSetEntry *se; CgSetEntry *se;
u32 current_cgset; u32 current_cgset;
bool needs_cgns_setup = false;
if (!rsti(me)->cg_set) if (!rsti(me)->cg_set)
return 0; return 0;
...@@ -1159,9 +1160,8 @@ int prepare_task_cgroup(struct pstree_item *me) ...@@ -1159,9 +1160,8 @@ int prepare_task_cgroup(struct pstree_item *me)
* just check that the cgns prefix string matches for all the entries * just check that the cgns prefix string matches for all the entries
* in the cgset, and only unshare if that's true. * in the cgset, and only unshare if that's true.
*/ */
needs_cgns_setup = !me->parent;
return move_in_cgroup(se, needs_cgns_setup); return move_in_cgroup(se, !me->parent);
} }
void fini_cgroup(void) void fini_cgroup(void)
......
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