Fix cross compile for make cross
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
parent
2acaf7ca82
commit
f85823b53d
11 changed files with 107 additions and 52 deletions
|
@ -3,9 +3,9 @@ package nsinit
|
|||
import (
|
||||
"fmt"
|
||||
"github.com/dotcloud/docker/pkg/libcontainer"
|
||||
"github.com/dotcloud/docker/pkg/system"
|
||||
"os"
|
||||
"os/exec"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// CommandFactory takes the container's configuration and options passed by the
|
||||
|
@ -15,22 +15,31 @@ type CommandFactory interface {
|
|||
Create(container *libcontainer.Container, console string, syncFd uintptr, args []string) *exec.Cmd
|
||||
}
|
||||
|
||||
type DefaultCommandFactory struct{}
|
||||
type DefaultCommandFactory struct {
|
||||
Root string
|
||||
}
|
||||
|
||||
// Create will return an exec.Cmd with the Cloneflags set to the proper namespaces
|
||||
// defined on the container's configuration and use the current binary as the init with the
|
||||
// args provided
|
||||
func (c *DefaultCommandFactory) Create(container *libcontainer.Container, console string, pipe uintptr, args []string) *exec.Cmd {
|
||||
// get our binary name so we can always reexec ourself
|
||||
name := os.Args[0]
|
||||
command := exec.Command(name, append([]string{
|
||||
// get our binary name from arg0 so we can always reexec ourself
|
||||
command := exec.Command(os.Args[0], append([]string{
|
||||
"-console", console,
|
||||
"-pipe", fmt.Sprint(pipe),
|
||||
"-root", c.Root,
|
||||
"init"}, args...)...)
|
||||
|
||||
command.SysProcAttr = &syscall.SysProcAttr{
|
||||
Cloneflags: uintptr(GetNamespaceFlags(container.Namespaces)),
|
||||
}
|
||||
system.SetCloneFlags(command, uintptr(GetNamespaceFlags(container.Namespaces)))
|
||||
command.Env = container.Env
|
||||
return command
|
||||
}
|
||||
|
||||
// GetNamespaceFlags parses the container's Namespaces options to set the correct
|
||||
// flags on clone, unshare, and setns
|
||||
func GetNamespaceFlags(namespaces libcontainer.Namespaces) (flag int) {
|
||||
for _, ns := range namespaces {
|
||||
flag |= ns.Value
|
||||
}
|
||||
return flag
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// +build linux
|
||||
|
||||
package nsinit
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
package nsinit
|
||||
|
||||
import (
|
||||
"github.com/dotcloud/docker/pkg/libcontainer"
|
||||
)
|
||||
|
||||
// getNamespaceFlags parses the container's Namespaces options to set the correct
|
||||
// flags on clone, unshare, and setns
|
||||
func GetNamespaceFlags(namespaces libcontainer.Namespaces) (flag int) {
|
||||
for _, ns := range namespaces {
|
||||
flag |= ns.Value
|
||||
}
|
||||
return flag
|
||||
}
|
|
@ -2,7 +2,6 @@ package main
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
"github.com/dotcloud/docker/pkg/libcontainer"
|
||||
"github.com/dotcloud/docker/pkg/libcontainer/nsinit"
|
||||
|
@ -18,11 +17,6 @@ var (
|
|||
pipeFd int
|
||||
)
|
||||
|
||||
var (
|
||||
ErrUnsupported = errors.New("Unsupported method")
|
||||
ErrWrongArguments = errors.New("Wrong argument count")
|
||||
)
|
||||
|
||||
func registerFlags() {
|
||||
flag.StringVar(&console, "console", "", "console (pty slave) path")
|
||||
flag.IntVar(&pipeFd, "pipe", 0, "sync pipe fd")
|
||||
|
@ -35,7 +29,7 @@ func main() {
|
|||
registerFlags()
|
||||
|
||||
if flag.NArg() < 1 {
|
||||
log.Fatal(ErrWrongArguments)
|
||||
log.Fatalf("wrong number of argments %d", flag.NArg())
|
||||
}
|
||||
container, err := loadContainer()
|
||||
if err != nil {
|
||||
|
@ -71,7 +65,7 @@ func main() {
|
|||
log.Fatal(err)
|
||||
}
|
||||
if flag.NArg() < 2 {
|
||||
log.Fatal(ErrWrongArguments)
|
||||
log.Fatalf("wrong number of argments %d", flag.NArg())
|
||||
}
|
||||
syncPipe, err := nsinit.NewSyncPipeFromFd(0, uintptr(pipeFd))
|
||||
if err != nil {
|
||||
|
@ -112,5 +106,5 @@ func readPid() (int, error) {
|
|||
}
|
||||
|
||||
func newNsInit() (nsinit.NsInit, error) {
|
||||
return nsinit.NewNsInit(&nsinit.DefaultCommandFactory{}, &nsinit.DefaultStateWriter{root}), nil
|
||||
return nsinit.NewNsInit(&nsinit.DefaultCommandFactory{root}, &nsinit.DefaultStateWriter{root}), nil
|
||||
}
|
||||
|
|
19
libcontainer/nsinit/unsupported.go
Normal file
19
libcontainer/nsinit/unsupported.go
Normal file
|
@ -0,0 +1,19 @@
|
|||
// +build !linux
|
||||
|
||||
package nsinit
|
||||
|
||||
import (
|
||||
"github.com/dotcloud/docker/pkg/libcontainer"
|
||||
)
|
||||
|
||||
func (ns *linuxNs) Exec(container *libcontainer.Container, term Terminal, args []string) (int, error) {
|
||||
return -1, libcontainer.ErrUnsupported
|
||||
}
|
||||
|
||||
func (ns *linuxNs) ExecIn(container *libcontainer.Container, nspid int, args []string) (int, error) {
|
||||
return -1, libcontainer.ErrUnsupported
|
||||
}
|
||||
|
||||
func (ns *linuxNs) Init(container *libcontainer.Container, uncleanRootfs, console string, syncPipe *SyncPipe, args []string) error {
|
||||
return libcontainer.ErrUnsupported
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue