Make native driver use Exec func with different CreateCommand
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
parent
2afcf71b2c
commit
761fd72512
4 changed files with 19 additions and 5 deletions
10
libcontainer/nsinit/create.go
Normal file
10
libcontainer/nsinit/create.go
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
package nsinit
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
|
||||||
|
"github.com/dotcloud/docker/pkg/libcontainer"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CreateCommand func(container *libcontainer.Container, console, rootfs, dataPath, init string, childPipe *os.File, args []string) *exec.Cmd
|
|
@ -17,7 +17,7 @@ import (
|
||||||
|
|
||||||
// Exec performes setup outside of a namespace so that a container can be
|
// Exec performes setup outside of a namespace so that a container can be
|
||||||
// executed. Exec is a high level function for working with container namespaces.
|
// executed. Exec is a high level function for working with container namespaces.
|
||||||
func Exec(container *libcontainer.Container, term Terminal, rootfs, dataPath string, args []string, startCallback func()) (int, error) {
|
func Exec(container *libcontainer.Container, term Terminal, rootfs, dataPath string, args []string, createCommand CreateCommand, startCallback func()) (int, error) {
|
||||||
var (
|
var (
|
||||||
master *os.File
|
master *os.File
|
||||||
console string
|
console string
|
||||||
|
@ -39,7 +39,7 @@ func Exec(container *libcontainer.Container, term Terminal, rootfs, dataPath str
|
||||||
term.SetMaster(master)
|
term.SetMaster(master)
|
||||||
}
|
}
|
||||||
|
|
||||||
command := CreateCommand(container, console, rootfs, dataPath, os.Args[0], syncPipe.child, args)
|
command := createCommand(container, console, rootfs, dataPath, os.Args[0], syncPipe.child, args)
|
||||||
if err := term.Attach(command); err != nil {
|
if err := term.Attach(command); err != nil {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ func Exec(container *libcontainer.Container, term Terminal, rootfs, dataPath str
|
||||||
return command.ProcessState.Sys().(syscall.WaitStatus).ExitStatus(), nil
|
return command.ProcessState.Sys().(syscall.WaitStatus).ExitStatus(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateCommand will return an exec.Cmd with the Cloneflags set to the proper namespaces
|
// DefaultCreateCommand 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
|
// defined on the container's configuration and use the current binary as the init with the
|
||||||
// args provided
|
// args provided
|
||||||
//
|
//
|
||||||
|
@ -99,7 +99,7 @@ func Exec(container *libcontainer.Container, term Terminal, rootfs, dataPath str
|
||||||
// root: the path to the container json file and information
|
// root: the path to the container json file and information
|
||||||
// pipe: sync pipe to syncronize the parent and child processes
|
// pipe: sync pipe to syncronize the parent and child processes
|
||||||
// args: the arguemnts to pass to the container to run as the user's program
|
// args: the arguemnts to pass to the container to run as the user's program
|
||||||
func CreateCommand(container *libcontainer.Container, console, rootfs, dataPath, init string, pipe *os.File, args []string) *exec.Cmd {
|
func DefaultCreateCommand(container *libcontainer.Container, console, rootfs, dataPath, init string, pipe *os.File, args []string) *exec.Cmd {
|
||||||
// get our binary name from arg0 so we can always reexec ourself
|
// get our binary name from arg0 so we can always reexec ourself
|
||||||
env := []string{
|
env := []string{
|
||||||
"console=" + console,
|
"console=" + console,
|
||||||
|
|
|
@ -39,7 +39,7 @@ func main() {
|
||||||
exitCode, err = nsinit.ExecIn(container, nspid, os.Args[2:])
|
exitCode, err = nsinit.ExecIn(container, nspid, os.Args[2:])
|
||||||
} else {
|
} else {
|
||||||
term := nsinit.NewTerminal(os.Stdin, os.Stdout, os.Stderr, container.Tty)
|
term := nsinit.NewTerminal(os.Stdin, os.Stdout, os.Stderr, container.Tty)
|
||||||
exitCode, err = nsinit.Exec(container, term, "", dataPath, os.Args[2:], nil)
|
exitCode, err = nsinit.Exec(container, term, "", dataPath, os.Args[2:], nsinit.DefaultCreateCommand, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -7,6 +7,10 @@ import (
|
||||||
"github.com/dotcloud/docker/pkg/libcontainer"
|
"github.com/dotcloud/docker/pkg/libcontainer"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func Exec(container *libcontainer.Container, term Terminal, rootfs, dataPath string, args []string, createCommand CreateCommand, startCallback func()) (int, error) {
|
||||||
|
return -1, libcontainer.ErrUnsupported
|
||||||
|
}
|
||||||
|
|
||||||
func Init(container *libcontainer.Container, uncleanRootfs, consolePath string, syncPipe *SyncPipe, args []string) error {
|
func Init(container *libcontainer.Container, uncleanRootfs, consolePath string, syncPipe *SyncPipe, args []string) error {
|
||||||
return libcontainer.ErrUnsupported
|
return libcontainer.ErrUnsupported
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue