mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge branch 'add-libcontainer' of https://github.com/crosbymichael/docker into add-libcontainer
Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes <guillaume.charmes@docker.com> (github: creack)
This commit is contained in:
commit
ca42758368
6 changed files with 26 additions and 18 deletions
|
@ -17,7 +17,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
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
|
// Running in init mode
|
||||||
sysinit.SysInit()
|
sysinit.SysInit()
|
||||||
return
|
return
|
||||||
|
|
|
@ -68,7 +68,6 @@ func getDefaultTemplate() *libcontainer.Container {
|
||||||
libcontainer.GetNamespace("NEWNS"),
|
libcontainer.GetNamespace("NEWNS"),
|
||||||
libcontainer.GetNamespace("NEWUTS"),
|
libcontainer.GetNamespace("NEWUTS"),
|
||||||
libcontainer.GetNamespace("NEWIPC"),
|
libcontainer.GetNamespace("NEWIPC"),
|
||||||
libcontainer.GetNamespace("NEWUSER"),
|
|
||||||
libcontainer.GetNamespace("NEWPID"),
|
libcontainer.GetNamespace("NEWPID"),
|
||||||
libcontainer.GetNamespace("NEWNET"),
|
libcontainer.GetNamespace("NEWNET"),
|
||||||
},
|
},
|
||||||
|
|
|
@ -2,7 +2,6 @@ package native
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dotcloud/docker/execdriver"
|
"github.com/dotcloud/docker/execdriver"
|
||||||
"github.com/dotcloud/docker/pkg/cgroups"
|
"github.com/dotcloud/docker/pkg/cgroups"
|
||||||
|
@ -22,10 +21,6 @@ const (
|
||||||
Version = "0.1"
|
Version = "0.1"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
ErrNotSupported = errors.New("not supported")
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
execdriver.RegisterInitFunc(DriverName, func(args *execdriver.InitArgs) error {
|
execdriver.RegisterInitFunc(DriverName, func(args *execdriver.InitArgs) error {
|
||||||
var (
|
var (
|
||||||
|
@ -109,10 +104,13 @@ func (d *driver) Restore(c *execdriver.Command) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer f.Close()
|
|
||||||
if _, err := fmt.Fscanf(f, "%d", &nspid); err != nil {
|
if _, err := fmt.Fscanf(f, "%d", &nspid); err != nil {
|
||||||
|
f.Close()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
f.Close()
|
||||||
|
defer os.Remove(p)
|
||||||
|
|
||||||
proc, err := os.FindProcess(nspid)
|
proc, err := os.FindProcess(nspid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -85,7 +85,7 @@ func init() {
|
||||||
os.Setenv("TEST", "1")
|
os.Setenv("TEST", "1")
|
||||||
|
|
||||||
// Hack to run sys init during unit testing
|
// 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()
|
sysinit.SysInit()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,30 @@
|
||||||
package system
|
package system
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"runtime"
|
||||||
"syscall"
|
"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 {
|
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 {
|
if err != 0 {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
// +build linux,amd64
|
|
||||||
|
|
||||||
package system
|
|
||||||
|
|
||||||
// Via http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=7b21fddd087678a70ad64afc0f632e0f1071b092
|
|
||||||
const (
|
|
||||||
SYS_SETNS = 308
|
|
||||||
)
|
|
Loading…
Reference in a new issue