Skip to content

Commit

Permalink
libct/msMoveRoot: benefit from GetMounts filter
Browse files Browse the repository at this point in the history
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Mar 18, 2020
1 parent b946fc8 commit 27ab232
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions libcontainer/rootfs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -805,17 +805,22 @@ func pivotRoot(rootfs string) error {
}

func msMoveRoot(rootfs string) error {
mountinfos, err := mountinfo.GetMounts(nil)
mountinfos, err := mountinfo.GetMounts(func(info *mountinfo.Info) (skip, stop bool) {
skip = false
stop = false
// Collect every sysfs and proc file systems, except those under the container rootfs
if (info.Fstype != "proc" && info.Fstype != "sysfs") || strings.HasPrefix(info.Mountpoint, rootfs) {
skip = true
return
}
return
})
if err != nil {
return err
}

for _, info := range mountinfos {
p := info.Mountpoint
// Umount every syfs and proc file systems, except those under the container rootfs
if (info.Fstype != "proc" && info.Fstype != "sysfs") || filepath.HasPrefix(p, rootfs) {
continue
}
// Be sure umount events are not propagated to the host.
if err := unix.Mount("", p, "", unix.MS_SLAVE|unix.MS_REC, ""); err != nil {
return err
Expand Down

0 comments on commit 27ab232

Please sign in to comment.