Merge pull request #742 from LK4D4/carry_732

Fix setupDev logic in rootfs_linux.go
This commit is contained in:
Michael Crosby 2016-04-11 11:16:36 -07:00
commit f54e41f7f0
2 changed files with 76 additions and 2 deletions

View File

@ -25,6 +25,16 @@ import (
const defaultMountFlags = syscall.MS_NOEXEC | syscall.MS_NOSUID | syscall.MS_NODEV
// setupDev returns true if /dev needs to be set up.
func needsSetupDev(config *configs.Config) bool {
for _, m := range config.Mounts {
if m.Device == "bind" && (m.Destination == "/dev" || m.Destination == "/dev/") {
return false
}
}
return true
}
// setupRootfs sets up the devices, mount points, and filesystems for use inside a
// new mount namespace.
func setupRootfs(config *configs.Config, console *linuxConsole, pipe io.ReadWriter) (err error) {
@ -32,7 +42,7 @@ func setupRootfs(config *configs.Config, console *linuxConsole, pipe io.ReadWrit
return newSystemError(err)
}
setupDev := len(config.Devices) != 0
setupDev := needsSetupDev(config)
for _, m := range config.Mounts {
for _, precmd := range m.PremountCmds {
if err := mountCmd(precmd); err != nil {

View File

@ -2,7 +2,11 @@
package libcontainer
import "testing"
import (
"testing"
"github.com/opencontainers/runc/libcontainer/configs"
)
func TestCheckMountDestOnProc(t *testing.T) {
dest := "/rootfs/proc/"
@ -35,3 +39,63 @@ func TestCheckMountRoot(t *testing.T) {
t.Fatal(err)
}
}
func TestNeedsSetupDev(t *testing.T) {
config := &configs.Config{
Mounts: []*configs.Mount{
{
Device: "bind",
Source: "/dev",
Destination: "/dev",
},
},
}
if needsSetupDev(config) {
t.Fatal("expected needsSetupDev to be false, got true")
}
}
func TestNeedsSetupDevStrangeSource(t *testing.T) {
config := &configs.Config{
Mounts: []*configs.Mount{
{
Device: "bind",
Source: "/devx",
Destination: "/dev",
},
},
}
if needsSetupDev(config) {
t.Fatal("expected needsSetupDev to be false, got true")
}
}
func TestNeedsSetupDevStrangeDest(t *testing.T) {
config := &configs.Config{
Mounts: []*configs.Mount{
{
Device: "bind",
Source: "/dev",
Destination: "/devx",
},
},
}
if !needsSetupDev(config) {
t.Fatal("expected needsSetupDev to be true, got false")
}
}
func TestNeedsSetupDevStrangeSourceDest(t *testing.T) {
config := &configs.Config{
Mounts: []*configs.Mount{
{
Device: "bind",
Source: "/devx",
Destination: "/devx",
},
},
}
if !needsSetupDev(config) {
t.Fatal("expected needsSetupDev to be true, got false")
}
}