Skip to content

Commit 91ca331

Browse files
committed
chroot when no mount namespaces is provided
Signed-off-by: Michael Crosby <[email protected]>
1 parent c4e4bb0 commit 91ca331

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

libcontainer/rootfs_linux.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ func prepareRootfs(pipe io.ReadWriter, iConfig *initConfig) (err error) {
100100

101101
if config.NoPivotRoot {
102102
err = msMoveRoot(config.Rootfs)
103-
} else {
103+
} else if config.Namespaces.Contains(configs.NEWNS) {
104104
err = pivotRoot(config.Rootfs)
105+
} else {
106+
err = chroot(config.Rootfs)
105107
}
106108
if err != nil {
107109
return newSystemErrorWithCause(err, "jailing process inside rootfs")
@@ -702,6 +704,10 @@ func msMoveRoot(rootfs string) error {
702704
if err := unix.Mount(rootfs, "/", "", unix.MS_MOVE, ""); err != nil {
703705
return err
704706
}
707+
return chroot(rootfs)
708+
}
709+
710+
func chroot(rootfs string) error {
705711
if err := unix.Chroot("."); err != nil {
706712
return err
707713
}

libcontainer/standard_init_linux.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,9 @@ func (l *linuxStandardInit) Init() error {
6565
}
6666

6767
label.Init()
68-
69-
// prepareRootfs() can be executed only for a new mount namespace.
70-
if l.config.Config.Namespaces.Contains(configs.NEWNS) {
71-
if err := prepareRootfs(l.pipe, l.config); err != nil {
72-
return err
73-
}
68+
if err := prepareRootfs(l.pipe, l.config); err != nil {
69+
return err
7470
}
75-
7671
// Set up the console. This has to be done *before* we finalize the rootfs,
7772
// but *after* we've given the user the chance to set up all of the mounts
7873
// they wanted.

0 commit comments

Comments
 (0)