Skip to content

Commit

Permalink
Merge branch 'add-libcontainer' of https://github.com/crosbymichael/d…
Browse files Browse the repository at this point in the history
…ocker into add-libcontainer

Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes <guillaume.charmes@docker.com> (github: creack)
  • Loading branch information
creack committed Feb 25, 2014
2 parents 91bf120 + de08340 commit ca42758
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

func main() {
if selfPath := utils.SelfPath(); selfPath == "/sbin/init" || strings.Contains(selfPath, ".dockerinit") {
if selfPath := utils.SelfPath(); strings.Contains(selfPath, ".dockerinit") {
// Running in init mode
sysinit.SysInit()
return
Expand Down
1 change: 0 additions & 1 deletion execdriver/native/default_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ func getDefaultTemplate() *libcontainer.Container {
libcontainer.GetNamespace("NEWNS"),
libcontainer.GetNamespace("NEWUTS"),
libcontainer.GetNamespace("NEWIPC"),
libcontainer.GetNamespace("NEWUSER"),
libcontainer.GetNamespace("NEWPID"),
libcontainer.GetNamespace("NEWNET"),
},
Expand Down
10 changes: 4 additions & 6 deletions execdriver/native/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package native

import (
"encoding/json"
"errors"
"fmt"
"github.com/dotcloud/docker/execdriver"
"github.com/dotcloud/docker/pkg/cgroups"
Expand All @@ -22,10 +21,6 @@ const (
Version = "0.1"
)

var (
ErrNotSupported = errors.New("not supported")
)

func init() {
execdriver.RegisterInitFunc(DriverName, func(args *execdriver.InitArgs) error {
var (
Expand Down Expand Up @@ -109,10 +104,13 @@ func (d *driver) Restore(c *execdriver.Command) error {
if err != nil {
return err
}
defer f.Close()
if _, err := fmt.Fscanf(f, "%d", &nspid); err != nil {
f.Close()
return err
}
f.Close()
defer os.Remove(p)

proc, err := os.FindProcess(nspid)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion integration/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func init() {
os.Setenv("TEST", "1")

// Hack to run sys init during unit testing
if selfPath := utils.SelfPath(); selfPath == "/sbin/init" || strings.Contains(selfPath, ".dockerinit") {
if selfPath := utils.SelfPath(); strings.Contains(selfPath, ".dockerinit") {
sysinit.SysInit()
return
}
Expand Down
21 changes: 20 additions & 1 deletion pkg/system/setns_linux.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
package system

import (
"errors"
"fmt"
"runtime"
"syscall"
)

var (
ErrNotSupportedPlatform = errors.New("platform and architecture is not supported")
)

// Via http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=7b21fddd087678a70ad64afc0f632e0f1071b092
//
// We need different setns values for the different platforms and arch
// We are declaring the macro here because the SETNS syscall does not exist in th stdlib
var setNsMap = map[string]uintptr{
"linux/amd64": 308,
}

func Setns(fd uintptr, flags uintptr) error {
_, _, err := syscall.RawSyscall(SYS_SETNS, fd, flags, 0)
ns, exists := setNsMap[fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH)]
if !exists {
return ErrNotSupportedPlatform
}
_, _, err := syscall.RawSyscall(ns, fd, flags, 0)
if err != 0 {
return err
}
Expand Down
8 changes: 0 additions & 8 deletions pkg/system/setns_linux_amd64.go

This file was deleted.

0 comments on commit ca42758

Please sign in to comment.