Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Fix compilation with golang 1.3(uid/gid mappings is unsupported) #374

Merged
merged 1 commit into from
Feb 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix compilation with golang 1.3(uid/gid mappings is unsupported)
Signed-off-by: Alexander Morozov <lk4d4@docker.com>
  • Loading branch information
LK4D4 committed Feb 12, 2015
commit fe9f7668957641a404b0d2c8850f104df591e7f2
31 changes: 7 additions & 24 deletions linux_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (c *linuxContainer) newParentProcess(p *Process, doInit bool) (parentProces
if !doInit {
return c.newSetnsProcess(p, cmd, parentPipe, childPipe), nil
}
return c.newInitProcess(p, cmd, parentPipe, childPipe), nil
return c.newInitProcess(p, cmd, parentPipe, childPipe)
}

func (c *linuxContainer) commandTemplate(p *Process, childPipe *os.File) (*exec.Cmd, error) {
Expand All @@ -163,11 +163,14 @@ func (c *linuxContainer) commandTemplate(p *Process, childPipe *os.File) (*exec.
return cmd, nil
}

func (c *linuxContainer) newInitProcess(p *Process, cmd *exec.Cmd, parentPipe, childPipe *os.File) *initProcess {
func (c *linuxContainer) newInitProcess(p *Process, cmd *exec.Cmd, parentPipe, childPipe *os.File) (*initProcess, error) {
t := "_LIBCONTAINER_INITTYPE=standard"
cloneFlags := c.config.Namespaces.CloneFlags()
if cloneFlags&syscall.CLONE_NEWUSER != 0 {
c.addUidGidMappings(cmd.SysProcAttr)
if err := c.addUidGidMappings(cmd.SysProcAttr); err != nil {
// mappings is not supported
return nil, err
}
// Default to root user when user namespaces are enabled.
if cmd.SysProcAttr.Credential == nil {
cmd.SysProcAttr.Credential = &syscall.Credential{}
Expand All @@ -182,7 +185,7 @@ func (c *linuxContainer) newInitProcess(p *Process, cmd *exec.Cmd, parentPipe, c
parentPipe: parentPipe,
manager: c.cgroupManager,
config: c.newInitConfig(p),
}
}, nil
}

func (c *linuxContainer) newSetnsProcess(p *Process, cmd *exec.Cmd, parentPipe, childPipe *os.File) *setnsProcess {
Expand Down Expand Up @@ -210,26 +213,6 @@ func (c *linuxContainer) newInitConfig(process *Process) *initConfig {
}
}

// Converts IDMap to SysProcIDMap array and adds it to SysProcAttr.
func (c *linuxContainer) addUidGidMappings(sys *syscall.SysProcAttr) {
if c.config.UidMappings != nil {
sys.UidMappings = make([]syscall.SysProcIDMap, len(c.config.UidMappings))
for i, um := range c.config.UidMappings {
sys.UidMappings[i].ContainerID = um.ContainerID
sys.UidMappings[i].HostID = um.HostID
sys.UidMappings[i].Size = um.Size
}
}
if c.config.GidMappings != nil {
sys.GidMappings = make([]syscall.SysProcIDMap, len(c.config.GidMappings))
for i, gm := range c.config.GidMappings {
sys.GidMappings[i].ContainerID = gm.ContainerID
sys.GidMappings[i].HostID = gm.HostID
sys.GidMappings[i].Size = gm.Size
}
}
}

func newPipe() (parent *os.File, child *os.File, err error) {
fds, err := syscall.Socketpair(syscall.AF_LOCAL, syscall.SOCK_STREAM|syscall.SOCK_CLOEXEC, 0)
if err != nil {
Expand Down
13 changes: 13 additions & 0 deletions linux_container_nouserns.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// +build !go1.4

package libcontainer

import (
"fmt"
"syscall"
)

// not available before go 1.4
func (c *linuxContainer) addUidGidMappings(sys *syscall.SysProcAttr) error {
return fmt.Errorf("User namespace is not supported in golang < 1.4")
}
26 changes: 26 additions & 0 deletions linux_container_userns.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// +build go1.4

package libcontainer

import "syscall"

// Converts IDMap to SysProcIDMap array and adds it to SysProcAttr.
func (c *linuxContainer) addUidGidMappings(sys *syscall.SysProcAttr) error {
if c.config.UidMappings != nil {
sys.UidMappings = make([]syscall.SysProcIDMap, len(c.config.UidMappings))
for i, um := range c.config.UidMappings {
sys.UidMappings[i].ContainerID = um.ContainerID
sys.UidMappings[i].HostID = um.HostID
sys.UidMappings[i].Size = um.Size
}
}
if c.config.GidMappings != nil {
sys.GidMappings = make([]syscall.SysProcIDMap, len(c.config.GidMappings))
for i, gm := range c.config.GidMappings {
sys.GidMappings[i].ContainerID = gm.ContainerID
sys.GidMappings[i].HostID = gm.HostID
sys.GidMappings[i].Size = gm.Size
}
}
return nil
}
4 changes: 3 additions & 1 deletion nsinit/oom.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ var oomCommand = cli.Command{
if err != nil {
log.Fatal(err)
}
for range n {
for x := range n {
// hack for calm down go1.4 gofmt
_ = x
log.Printf("OOM notification received")
}
},
Expand Down