2db754f3ee
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
37 lines
1.2 KiB
Go
37 lines
1.2 KiB
Go
package nsinit
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
|
|
"github.com/dotcloud/docker/pkg/libcontainer"
|
|
"github.com/dotcloud/docker/pkg/system"
|
|
)
|
|
|
|
// CommandFactory takes the container's configuration and options passed by the
|
|
// parent processes and creates an *exec.Cmd that will be used to fork/exec the
|
|
// namespaced init process
|
|
type CommandFactory interface {
|
|
Create(container *libcontainer.Container, console string, syncFd *os.File, args []string) *exec.Cmd
|
|
}
|
|
|
|
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 *os.File, args []string) *exec.Cmd {
|
|
// get our binary name from arg0 so we can always reexec ourself
|
|
command := exec.Command(os.Args[0], append([]string{
|
|
"-console", console,
|
|
"-pipe", "3",
|
|
"-root", c.Root,
|
|
"init"}, args...)...)
|
|
|
|
system.SetCloneFlags(command, uintptr(GetNamespaceFlags(container.Namespaces)))
|
|
command.Env = container.Env
|
|
command.ExtraFiles = []*os.File{pipe}
|
|
return command
|
|
}
|