Skip to content

Commit 8779fa5

Browse files
author
Mrunal Patel
authored
Merge pull request #1168 from hqhq/fix_nsexec_comments
More fix to nsexec.c's comments
2 parents 99a6023 + 84a4218 commit 8779fa5

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

libcontainer/nsenter/nsexec.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -598,11 +598,11 @@ void nsexec(void)
598598

599599
/*
600600
* Stage 1: We're in the first child process. Our job is to join any
601-
* provided user namespaces in the netlink payload. If we've been
602-
* asked to CLONE_NEWUSER, we will unshare the user namespace and
603-
* ask our parent (stage 0) to set up our user mappings for us.
604-
* Then, we unshare the rest of the requested namespaces and
605-
* create a new child (stage 2: JUMP_INIT). We then send the
601+
* provided namespaces in the netlink payload and unshare all
602+
* of the requested namespaces. If we've been asked to
603+
* CLONE_NEWUSER, we will ask our parent (stage 0) to set up
604+
* our user mappings for us. Then, we create a new child
605+
* (stage 2: JUMP_INIT) for PID namespace. We then send the
606606
* child's PID to our parent (stage 0).
607607
*/
608608
case JUMP_CHILD: {
@@ -660,7 +660,15 @@ void nsexec(void)
660660
bail("failed to sync with parent: SYNC_USERMAP_ACK: got %u", s);
661661
}
662662

663-
/* TODO: What about non-namespace clone flags that we're dropping here? */
663+
/*
664+
* TODO: What about non-namespace clone flags that we're dropping here?
665+
*
666+
* We fork again because of PID namespace, setns(2) or unshare(2) don't
667+
* change the PID namespace of the calling process, because doing so
668+
* would change the caller's idea of its own PID (as reported by getpid()),
669+
* which would break many applications and libraries, so we must fork
670+
* to actually enter the new PID namespace.
671+
*/
664672
child = clone_parent(&env, JUMP_INIT);
665673
if (child < 0)
666674
bail("unable to fork: init_func");

0 commit comments

Comments
 (0)